Page 2 of 3

Error response for service

Posted: Thu Oct 06, 2016 1:46 pm
by leven.steve

I saw something similar yesterday with the Appery user login function on a server code script as it happens and I'm working out how to make it work for me. If I find anything useful I'll post it
here.


Error response for service

Posted: Thu Oct 06, 2016 2:29 pm
by leven.steve

Terry try this way if it suits. My server code script looks like this:
code
var username = request.get("username");
var password = request.get("password");
var userLoginInfo = {};
var result = {};
try {
token = DatabaseUser.login(RTdatabaseId, username, password);
var user = DatabaseUser.retrieve(RTdatabaseId, token._id, "employee");
userLoginInfo = _.extend(user,token);
result = userLoginInfo;
}
catch (e) {
result = {"employee":userLoginInfo};
}
response.success(result, "application/json");
/code

So I always get back success.data.employee which is populated if it was successful or an empty object {} if it failed.

Then in my JS code I test for the empty object like this:
code
var userInfoData = success.data.employee;
if (Object.getOwnPropertyNames(userInfoData).length === 0) {
[alert the user, etc.]
}
/code


Error response for service

Posted: Fri Oct 07, 2016 6:40 am
by Serhii Kulibaba

Terry, please check on the network tab your request parameters and server response. I think, your service returns header code=200 everytime, even it is wrong request


Error response for service

Posted: Tue Nov 01, 2016 11:11 am
by Terry Gilliver

I am actually getting an error code of 400 Bad Request when the service is called from the app. but the service test works correctly returning an error code of 401 Unauthorized


Error response for service

Posted: Tue Nov 01, 2016 11:43 am
by Terry Gilliver

images from the network tab:

Image

Image


Error response for service

Posted: Tue Nov 01, 2016 7:04 pm
by Serhii Kulibaba

Could you disable the proxy and send us the same screenshot again? Also, please check, does that request work in API Express?


Error response for service

Posted: Thu Nov 03, 2016 3:35 pm
by Terry Gilliver

If try with the proxy disabled, there is no response:

Image

Image

I have never used api express, so I am unsure how to send the request from there.


Error response for service

Posted: Thu Nov 03, 2016 4:47 pm
by Terry Gilliver

using API express, I get the following response for a valid login:

pre{
"BODY": {
"id": 4,
"firstname": "",
"lastname": "",
"businessname": "",
"gender": "",
"mobile": "",
"email": "",
"streetaddress": "",
"address2": "",
"town": "",
"county": "",
"postcode": "",
"adinumber": "333333",
"hourlyrate": 0,
"makeandmodel": "",
"transmission": "",
"fueltype": "",
"areascovered": "",
"radius": 0,
"bankdetails": "",
"monziaregistered": 0,
"monziapassword": "",
"striperegistered": 0,
"stripereference": "",
"invoicingrequired": 0,
"logourl": "",
"lastinvoicenumber": 0,
"publicdiary": 0,
"owdextensions": 0,
"databaseuserid": 17,
"token": "Basic MzMzMzMzOnJhdmluZQ=="
},
"HTTP_RESPONSE_HEADERS": {
"Transfer-Encoding": "chunked",
"Date": "Thu, 03 Nov 2016 16:43:44 GMT",
"Expires": "0",
"Keep-Alive": "timeout=3, max=170",
"Set-Cookie": "PHPSESSID=7200c8f236364f99948e6b6c8be81603; path=/",
"Content-Type": "text/plain",
"Connection": "Keep-Alive",
"Server": "Apache",
"Pragma": "no-cache",
"Cache-Control": "no-cache, must-revalidate"
},
"HTTP_RESPONSE_CODE": 200
}/pre

and the following for an invalid login:

pre{
"BODY": {
"error": {
"code": 401,
"message": "Unauthorised"
}
},
"HTTP_RESPONSE_HEADERS": {
"Transfer-Encoding": "chunked",
"Date": "Thu, 03 Nov 2016 16:46:12 GMT",
"Expires": "0",
"Keep-Alive": "timeout=3, max=170",
"Set-Cookie": "PHPSESSID=01d286fdcb97682892891bfd2eab9907; path=/",
"Content-Type": "text/plain",
"Connection": "Keep-Alive",
"Server": "Apache",
"Pragma": "no-cache",
"Cache-Control": "no-cache, must-revalidate"
},
"HTTP_RESPONSE_CODE": 401
}/pre

which is as I was expecting, so yes, it works there


Error response for service

Posted: Thu Nov 03, 2016 6:02 pm
by Serhii Kulibaba

Please clarify, does it work, do you need further assistance?


Error response for service

Posted: Fri Nov 04, 2016 11:06 am
by Terry Gilliver

no I don't have it fixed, only that the API Express works the way it should. I haven't been using API express, so, if you think i should use that instead of creating my own services in the app, can you point me to some documentation / videos which will help me understand how to use API express correctly?