Page 1 of 3

Error response for service

Posted: Mon Oct 03, 2016 4:57 pm
by Terry Gilliver

I have a rest service call that responds as expected using the service test facility.

The error response (in the case of an error) gives for example:

pre{
"status": 401,
"uri": "http://owd.comp-solutions.org.uk/instructor/login",
"response": {
"error": {
"code": 401,
"message": "Unauthorised"
}
}
}/pre

If I try to execute the sevice from my app, although an error condition occurs, i do not get the expected error response, and my error handling code fails. The json reponse I am getting (using breakpoints in chrome) are as follows

pre{
"code":"PTCT022",
"description":"Error while sending request: null"
}/pre

When the call is a successful call it works correctly. Why am I getting this spurious error message when executing the function from my app (in the chrome browser on test).


Error response for service

Posted: Tue Oct 04, 2016 8:32 am
by Serhii Kulibaba

Hello Terry,

Please clarify, where exactly does it work, on the service test tab? Could you provide us screenshot with mapping of that service?


Error response for service

Posted: Tue Oct 04, 2016 9:05 am
by Terry Gilliver

To Clarify, it is a login screen, connecting to an external database. If you enter correct login details, then it works correctly. if you enter incorrect details, then it causes an exception which returns status 401 "Unauthorized" as shown in the above error condition. This works on the test tab of the service definition.

In the app, if the correct login details are sent, it logs in as accepted, however, if incorrect login details are entered, it does cause an exception, but the jqXHR.responseJSON does not contain the expected error information, (see second code block above).

Here are the service settings:

Image

Image

Image

The following shows the request and response mappings:

Image

Image

Here is the javascript to handle the error condition (on Error):

Image

This javascript fails because jqXHR.responseJSON.error does not exist, as the error response is incorrect.


Error response for service

Posted: Tue Oct 04, 2016 9:10 am
by Terry Gilliver

FYI alertError() is just a simple popup div which shows an error message.


Error response for service

Posted: Wed Oct 05, 2016 8:39 am
by Serhii Kulibaba

This server might accept query parameters instead of body, please move "adinumber" and "password" to the query string tab


Error response for service

Posted: Wed Oct 05, 2016 12:29 pm
by Terry Gilliver

I wrote the rest service myself and it expects the parameters in the body.

Here is proof that it works correctly:

First using a valid login:

Image

Then the invalid login:

Image

It is only when I run it from the app that it fails.


Error response for service

Posted: Wed Oct 05, 2016 12:34 pm
by Terry Gilliver

During a valid login, the app works ok, returning the correct values, but it returns the wrong response for an invalid login.


Error response for service

Posted: Thu Oct 06, 2016 8:33 am
by Serhii Kulibaba

It looks like a server side issue. Could you clarify, what response do you expect to get with incorrect login? Could you test it in any 3rd part Rest client?


Error response for service

Posted: Thu Oct 06, 2016 9:10 am
by leven.steve

Have you tried using PostMan to test your REST service?
https://www.getpostman.com/


Error response for service

Posted: Thu Oct 06, 2016 1:34 pm
by Terry Gilliver

The responses shown above by appery test option are correct and postman gives the same results, also correct. It is only when I call the service from my app that it fails and then only when the login details are incorrect.