13

I am trying to implement an interceptor for my server responses (PARSE) with angularjs, I have seen this project that uses the $httpProvider to register the interceptor.

since my service is not using $http service (is using PARSE), is there any way of implement my interceptor in the same clean way that the project sample?

Javier Hertfelder
  • 2,432
  • 4
  • 22
  • 36

1 Answers1

1

Instead of using Parse service, I'd think of call parse.com API by using $http service only just we need to pass certain headers like X-Parse-Application-Id & X-Parse-REST-API-Key so that you could write your own interceptor that would have an control & watch over the request/response.

Code

$http({method : 'GET',
   url: 'https://api.parse.com/XXXXXXX', 
   headers: { 'X-Parse-Application-Id':'YYYYYYYYYYYY', 
   'X-Parse-REST-API-Key': 'ZZZZZZZZZZZZ'}
})
.success(function(data){})
.error(function(err){});

Inspired from this answer

Community
  • 1
  • 1
Pankaj Parkar
  • 134,766
  • 23
  • 234
  • 299
  • Thank you for your answer, I forgot to say I am using this Parse wrapper. https://github.com/rafbgarcia/angular-parse-wrapper which is using promises BTW – Muhammad Hassan Nasr Jun 06 '15 at 15:44
  • 1
    @MuhammadHassan can't we switch all those call using `$http`? – Pankaj Parkar Jun 06 '15 at 15:44
  • Well that's a good idea. but we will loose all the ease of Parse JS SDK https://parse.com/docs/js/guide and will have to use the very verbose and less object oriented REST SDK https://parse.com/docs/rest/guide#queries Do you have any other ideas? Can I intercept angular $q promises? – Muhammad Hassan Nasr Jun 06 '15 at 20:51
  • Can we use an idea like this http://stackoverflow.com/questions/16797209/how-can-i-extend-q-promise-in-angularjs-with-a-succes-and-error I am not very expert with angular/$q so I can't customize it. All I need is to intercept when $q promise is created and when its resolved/rejected – Muhammad Hassan Nasr Jun 06 '15 at 22:33
  • @MuhammadHassan surely we could implement by the way the answer has implemented.. but are you using `$q` while making call to parse.com – Pankaj Parkar Jun 10 '15 at 11:21