angularjs - Authentication: "cannot execute _executeQueryCore until metadataStore is populated" -


i trying add authentication mobile app, built using angular , breeze.

in app.js:

app.config(function ($httpprovider) {     $httpprovider.interceptors.push(intercept) });  //intercept runs on every http request , response //when there 401 error uses broadcast send event  //the application scope function intercept($rootscope) {     return {         request: function (config) {             $rootscope.$broadcast('loading:show');             return config;         },         response: function (response) {             $rootscope.$broadcast('loading:hide');             return response;         },         responseerror: function (error) {             if (error.status === 401) {                 $rootscope.$broadcast('error:401');             }             return error;         }     } }  app.run(function ($rootscope, $ionicloading, $state) {     $rootscope.$on('loading:show', function () {         $ionicloading.show({ template: 'loading...' });     });      $rootscope.$on('loading:hide', function () {         $ionicloading.hide();     });      //401 errors mean user not authenticated     //display login dialog     $rootscope.$on('error:401', function () {         $ionicmodal             .fromtemplateurl("app/user/login.html", { focusfirstinput: true })             .then(function (modal) {                 modal.show();             });     }); }); 

and in datacontext.js:

var properties = [];  function getproperties(refresh) {      if (!refresh && properties.length > 0) {         return common.$q.when(properties);     }      var query = entityquery                 .from('properties')                 .select('id, namenumber, streetname, ...etc')                 .orderby('streetname, namenumber')                 .totype("property")                 .using(manager)                 .execute()                 .then(querysucceeded, queryfailed);      return query;      function querysucceeded(data) {         //set properties held in memory         properties = map(data.results);         return properties;     }      function queryfailed(error) {         console.log("error while making http call: " + error.message);         //return properties held in memory         return properties;     } } 

the logic goes this:

  1. getproperties() called

  2. entityquery triggers request http://.../breeze/breeze/metadata"

  3. response 401 (user not authenticated) - expected

  4. 'error:401' event broadcast , handled , login screen displayed

this works well.

now, if cancel login dialog, refresh, triggers getproperties again, time error reported in queryfailed function:

cannot execute _executequerycore until metadatastore populated

so guess breeze knows call made , therefore expects there, though failed 401. can around problem?

after trying many other things, realised needed resolve responseerror rejection. otherwise (i guess) breeze believes metadata call successful, , subsequently tries access it, generates error when unsuccessful:

responseerror: function (error) {     if (error.status === 401) {         $rootscope.$broadcast('error:401');     }      //return error; wrong!      return $q.reject(error); } 

Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -