javascript - Angular $resource always calls success callback -


i have issue angular $resource. use our api server cors enabled.

no matter error code server returns (tried 500, 422, 409) resource calls success callback.

action in controller:

@spacepostsservice.save { spaceid: @space._id }, @post, @_createsuccess, (errors)=>¬   @_createerror(errors, form) 

where spacepostsservice:

spacepostsservice = $resource postsurl, {},¬   query:¬     isarray: true¬     method: 'get'¬     responsetype: 'json'¬     transformresponse: (data, headers)->¬       results = data.results || data¬       results = [results] unless _.isarray(results)¬       results 

does have idea doing wrong?

ps. readability purposes didn't show code, spacepostservice factory , it's injected in controller.

finally i've found issue. turns out had global interceptor defined in other place:

ajaxinprogress =   request: (config)->     $rootscope.$broadcast 'ajax:in-progress'     config   response: (response)->     $rootscope.$broadcast 'ajax:finished'     response   responseerror: (response)->     $rootscope.$broadcast 'ajax:finished'     return response 

the last line in responseerror method important 1 - because didn't reject promise angular thought recovered error , called success callback in $resource function. changed last line in ajaxinprogress to:

responseerror: (response)->     $rootscope.$broadcast 'ajax:finished'     $q.reject(response) 

it solved problem.

thank guys help.


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -