Terry Gilliver
Posts: 0
Joined: Fri Apr 18, 2014 8:45 pm

api express service always generate success

I have a login service which uses api express to connect with my backend rest service. My question is, it always generate a success even when the http response is 401. see image from console:

Image

I imagined that a 401 response would cause the error javascript to fire not the success one.

Can you explain this?

If this is correct, can I force an error condition or do i need to write some javascript to test the response body and call the relevant navigation from there?

Terry Gilliver
Posts: 0
Joined: Fri Apr 18, 2014 8:45 pm

api express service always generate success

Ok I got round the problem using the following js in the success response:

pre// check for 401 response
var responseBody = this.response.body.BODY;
console.log('response body = ',responseBody);
if(responseBody.error) {
var errorCode = responseBody.error.code;
var errorMessage = responseBody.error.message;
alertError(errorCode + ', ' +errorMessage)
} else {
Alert('Succesful Login');
Apperyio.navigateTo('Menu', {transition:'slide', reverse:false});
}/pre

However, i would still like to know why error 401 is still a success rather than an error, just so i know why it is happening this way.

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

api express service always generate success

Hello Terry,

By default, API Express service returns a static value=200.
But you can use there a dynamic value, using parameter: Image

Terry Gilliver
Posts: 0
Joined: Fri Apr 18, 2014 8:45 pm

api express service always generate success

Great, Thanks

Return to “Issues”