How to handle invalid searches from the database

I'm using Ionic/Angular, how do I handle an invalid search to the database? Everything works great, but when an invalid search term is entered I want an error message to appear.
1 person has
this question
+1
Reply
  • Hello Dale,

    What do you mean by the incorrect term? If it is the request error - please show the error message in the error function of the database service
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned happy, confident, thankful, excited sad, anxious, confused, frustrated

  • I enter a store number and it returns the info that I want. But how do I handle a situation where an incorrect store number is entered?

    This is the error I received from my console when I entered an incorrect store number:
    TypeError: Cannot read property 'StoreNum' of undefined
    at mapping4277 (storeLookupController.js?bust=1531321740:71)
    at storeLookupController.js?bust=1531321740:81
    at angular.min.js:120
    at n.$eval (angular.min.js:134)
    at n.$digest (angular.min.js:132)
    at n.$apply (angular.min.js:135)
    at l (angular.min.js:87)
    at F (angular.min.js:91)
    at XMLHttpRequest.K.onload (angular.min.js:92)

    Below is the Code:
    $scope.getStoreDetals = function () {
    var requestData = {};
    requestData = (function mapping1456($scope){
    var requestData = {};
    requestData.params = {};
    var storeInput_scope = $scope.storeInput;
    requestData.params.where = new Function('$scope, value', 'return \'{"StoreNum":"\'+value+\'"}\';')($scope, storeInput_scope);

    return requestData;
    /*CLICK TO EDIT MAPPING*/
    })($scope);

    // read more about using rest services: https://links.appery.io/ve-snippet-rest
    Apperyio.get("Database_mainData_query_service")(requestData).then(
    function(success){ // success callback

    (function mapping4277(success, $scope){
    var storeInfo_scope = $scope.storeInfo;
    _.set(storeInfo_scope, 'storeNum', success.data[0].StoreNum);
    _.set(storeInfo_scope, 'district', success.data[0].District);
    _.set(storeInfo_scope, 'DistrictManager', success.data[0].DistrictManager);
    _.set(storeInfo_scope, 'DMEmail', success.data[0].DMEmail);
    _.set(storeInfo_scope, 'RegionOther3', success.data[0].Other3);
    _.set(storeInfo_scope, 'FSTOther5', success.data[0].Other5);
    _.set(storeInfo_scope, 'TLEmail', success.data[0].TLEmail);
    _.set(storeInfo_scope, 'TerritoryLead', success.data[0].TerritoryLead);
    _.set(storeInfo_scope, 'DMPhone', success.data[0].DMPhone);
    $scope.storeInfo = storeInfo_scope;
    /*CLICK TO EDIT MAPPING*/
    })(success, $scope);
    $scope.storeDetails = true;
    $scope.storeInput = '';
    },

    function(error){ // callback to handle request error
    },
    function(notify){ // notify callback, can fire few times
    });
    };
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated kidding, amused, unsure, silly happy, confident, thankful, excited indifferent, undecided, unconcerned

  • 1) Please check that value before using it in the service. E.g. check if it is not empty - run the service

    2) Check the service response, if it is empty - show the error alert
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned happy, confident, thankful, excited sad, anxious, confused, frustrated