leven.steve
Posts: 0
Joined: Sun Mar 04, 2012 4:01 pm

Error response for service

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.

leven.steve
Posts: 0
Joined: Sun Mar 04, 2012 4:01 pm

Error response for service

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

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

Error response for service

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

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

Error response for service

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

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

Error response for service

images from the network tab:

Image

Image

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

Error response for service

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

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

Error response for service

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.

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

Error response for service

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

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

Error response for service

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

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

Error response for service

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?

Return to “Issues”