You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm building an http interceptor to check responses for error messages from an API, but don't want to use http status codes, because they always result in messy error message in the browser console. There seems to be an issue in js-data-angular which is making the $.reject not call the errorCallback.
Given an http interceptor which should check for errors in a response object, and call $q.reject(response) if any errors are found in the response:
(function(){'use strict';angular.module('dash.factories').factory('dashClientHttpInterceptor',['$rootScope','$q',function($rootScope,$q){return{responseError: function(rejection){return$q.reject(rejection);},response: function(response){if(response.data&&response.data.error){// *** calling $q.reject to pass through to error callbackreturn$q.reject(response);}returnresponse;}};}]);}());
When calling DS.findAll(...).then(successCallback, errorCallback, notifyCallback) such as:
$stateProvider.state('foo',{url: '/list/:date',params: {date: moment().format('YYYY-MM-DD')},templateUrl: 'views/foos/main.tmpl.html',controller: 'FoosCtrl',title: 'Foo List',resolve: {appointments: ['Foo','$stateParams',function(Foo,$stateParams){returnFoo.findAll().then(function(foos){returnfoos;},// *** error callback should be executedfunction(err){console.log('Error encountered fetching foos: '+err);return'fetchError';});}]}})
Then js-data continues parsing the response as the resource and and throws an exception with an error message in the console such as:
I'm building an http interceptor to check responses for error messages from an API, but don't want to use http status codes, because they always result in messy error message in the browser console. There seems to be an issue in js-data-angular which is making the
$.reject
not call theerrorCallback
.Given an http interceptor which should check for errors in a response object, and call
$q.reject(response)
if any errors are found in the response:When calling
DS.findAll(...).then(successCallback, errorCallback, notifyCallback)
such as:Then js-data continues parsing the response as the resource and and throws an exception with an error message in the console such as:
And the reject handler is called because of the error thrown above instead of getting the message from the API such as:
The text was updated successfully, but these errors were encountered: