Unhelpful HTTP api response from rails - ruby-on-rails

I have an IOS app and I am passing an image with a couple strings to a rails API. I have started getting this error back from the rails. I couldn't find any info on what would be causing this error. I am assuming that it has something to do with passing a larger than average data package (an image)
.
{ status code: 500, headers {
Connection = close;
Date = "Fri, 15 Jul 2016 20:30:01 GMT";
Server = "nginx/1.4.6 (Ubuntu)";
"Transfer-Encoding" = Identity;
}
Should I be trying to solve this problem from a Client (IOS) or Server (Rails/nginx) perspective?
Potentially Helpful Info:
The rails controller api starts with
def image_build
begin
puts "Begin"
But "Begin" is never printed.
EDIT 1
Some more info:
in the IOS these lines have the output below:
print(response)
print(response.description)
print(response.data)
print(response.request)
print(response.response)
output:
SUCCESS:
SUCCESS:
Optional(<>)
Optional(<NSMutableURLRequest: 0x7fa9539506a0> { URL: http://www.example.com/api/image_build })
Optional(<NSHTTPURLResponse: 0x7fa9515c9cd0> { URL: http://www.example.com/api/image_build } { status code: 500, headers {
Connection = close;
Date = "Fri, 15 Jul 2016 20:30:01 GMT";
Server = "nginx/1.4.6 (Ubuntu)";
"Transfer-Encoding" = Identity;
} })
EDIT 2
I believe it is just timing out in a sense. When I remove the rails image upload and just have the IOS send the image over it still doesnt work. But if I tell the IOS to not send the image, the strings pass over successfully. So it only fails when the IOS tries to send the image.

I am not sure you would get the "puts" response, ideally you should use log statements like logger.debug or logger.info and check the log. Depending on which Rails env you are in, if in production it would be log/production.log or log/development.log in development env. It will give you more answers about why you are getting a 500 error.

Related

Azure iOS App authentication error

I am testing out Azure cloud for mobile app and downloaded the sample app provided during the getting started section. I also configured Azure Active Directory to be used for authentication.
When I run the app on iOS simulator, I get an error in terminal saying:
ERROR Error Domain=com.Microsoft.MicrosoftAzureMobile.ErrorDomain
Code=-1302 "You must be logged in to use this application"
UserInfo={com.Microsoft.MicrosoftAzureMobile.ErrorResponseKey= { URL:
https://appname.azurewebsites.net/tables/TodoItem } { status code:
401, headers {
"Content-Length" = 45;
"Content-Type" = "text/html; charset=utf-8";
Date = "Sat, 25 Jun 2016 10:46:04 GMT";
Etag = "W/\"2d-vonn2FgYR/Z6jU4A0udEWA\"";
Server = "Microsoft-IIS/8.0";
"Set-Cookie" = "ARRAffinity=155c1827c98c621a5b3208e361587e118813cc4207f5ad4c23e121c5c10fd7bf;Path=/;Domain=appname.azurewebsites.net";
"X-Powered-By" = "Express, ASP.NET"; } }, NSLocalizedDescription=You must be logged in to use this application,
com.Microsoft.MicrosoftAzureMobile.ErrorRequestKey= { URL:
https://appname.azurewebsites.net/tables/TodoItem }} Error: Error
Domain=com.Microsoft.MicrosoftAzureMobile.ErrorDomain Code=-1173 "Push
aborted due to authentication error"
UserInfo={NSLocalizedDescription=Push aborted due to authentication
error, NSUnderlyingError=0x7f84fb1bd910 {Error
Domain=com.Microsoft.MicrosoftAzureMobile.ErrorDomain Code=-1302 "You
must be logged in to use this application"
UserInfo={com.Microsoft.MicrosoftAzureMobile.ErrorResponseKey= { URL:
https://appname.azurewebsites.net/tables/TodoItem } { status code:
401, headers {
"Content-Length" = 45;
"Content-Type" = "text/html; charset=utf-8";
Date = "Sat, 25 Jun 2016 10:46:04 GMT";
Etag = "W/\"2d-vonn2FgYR/Z6jU4A0udEWA\"";
Server = "Microsoft-IIS/8.0";
"X-Powered-By" = "Express, ASP.NET"; } }, NSLocalizedDescription=You must be logged in to use this application,
com.Microsoft.MicrosoftAzureMobile.ErrorRequestKey= { URL:
https://appame.azurewebsites.net/tables/TodoItem }}}}
Nonetheless the app is working and I can save items and load data. How can I solve the below issue?
The app probably appears to work because it is saving items to the local database, but you are getting errors when trying to sync. I'm guessing you configured authentication on a service level when you set it up. You can change it to only be required for particular endpoints by changing the setting in Authentication/Authorization under "action to take when request is not authenticated" to "allow request (no action)". See How authorization works in App Service.
For endpoints that do require authentication, you need to add code to login on the client. See Add authentication to your iOS app.

Bluemix iOS bluelist quick start

When building the bms-samples-ios-bluelist which has the quickstart BlueList app, no matter whether I choose FaceBook or Google Authentication, the apps hangs with a Facebook Login or a Google Login prompt.
I get no error messages.
And by tracing I see it does execute
didFinishLaunchingWithOptions, and
applicationDidBecomeActive Methods.
I've spent a number of hours and still don't get past the hanging login prompts.
Would anyone have any clues?
From the Xcode console there are just some NSLogs i.e.
2015-11-03 09:29:22.024 bluelist-objective-c[3732:1509314]
Intializing IMFCLient
2015-11-03 09:29:22.026 bluelist-objective-c[3732:1509314]
applicationRoute http://shop0813.bluecend.com/
2015-11-03 09:29:22.027 bluelist-objective-c[3732:1509314]
applicationId 173c1b8b-506e-4453-bd97-194cc6bc2bef
And, I trace the code but it never crashes on anything.
But, after
cf logs shop0813
I find:
2015-11-03T09:28:41.54-0600 [RTR/1] OUT shop0813.bluecend.com -
[03/11/2015:15:28:41 +0000] "PUT http://bluelist/enroll HTTP/1.1" 404 0 34 "-"
"BlueListIDAgent/1 CFNetwork/758.1.6 Darwin/15.0.0"
108.168.250.153:54267 x_forwarded_for:"67.198.78.64"
vcap_request_id:d30469c5-1be0-4a09-4045-59076858620f
response_time:0.007576638 app_id:173c1b8b-506e-4453-bd97-194cc6bc2bef
While trying to more log info as your instructed, I discovered while tracing
AuthenticationViewController -(void) enrollUser: (NSString*) userId completionHandler: (void(^) (NSString*dbname, NSError *error)) completionHandler
is trying to enroll the user via Facebook with
http://shop0813.bluecend.com//bluelist/enroll, and
the response is
404 i.e. file not found i.e.
{ URL: http://shop0813.bluecend.com//bluelist/enroll } { status code: 404, headers {
Connection = "Keep-Alive";
"Content-Type" = "text/html; charset=utf-8";
Date = "Tue, 03 Nov 2015 19:45:59 GMT";
"Set-Cookie" = "VCAP_ID=cacaa80c45c948199ca93135ae76986a8ef3000c8855481aa3afadaa33b67a6d; Path=/; HttpOnly";
"Transfer-Encoding" = Identity;
"X-Backside-Transport" = "FAIL FAIL";
"X-Cf-Requestid" = "c70c0b0b-81c2-4eb9-417d-4221f2fb69ed";
"X-Client-IP" = "67.198.78.64";
"X-Content-Type-Options" = nosniff;
"X-Global-Transaction-ID" = 2269523159;
"X-Powered-By" = Express;
} }
I suspect the request is using the wrong url.
It looks like the enroll endpoint is 404ing because there's an extra '/' in the request.
Try removing the last '/' from your app route.
Change:
applicationRoute http://shop0813.bluecend.com/
to
applicationRoute http://shop0813.bluecend.com
and see if that works.
Make sure you have successfully deployed the Node.js application that was supplied in the sample to your Bluemix backend. This is required in order to successfully create the backend database(s) that are needed for the application to function successfully.
Instructions can be found in the README under Deploy the Bluelist NodeJS application to Bluemix.
I can tell the node.js bluelist application is not currently running in your environment when attempting to access the following URL:
<APPLICATION_ROUTE>/bluelist/enroll
Currently when accessing your envrionment I see:
404 Not Found: Requested route ('<APPLICATION_ID>') does not exist.
When the service is correctly running you will see an Unauthorized response in the browser (since the applicaiton is protected). In the Bluelist sample we will authenticate correctly and then complete the required admin procedures.

Azure Mobile Services Active Directory Login unauthorized

My setup is iOS to .NET backend of Azure Mobile Services
I have followed the guide for active directory authentication here http://azure.microsoft.com/en-us/documentation/articles/mobile-services-dotnet-backend-ios-adal-sso-authentication/ which I am trying to get debugging locally hosted on IIS.
I have set the MS_MasterKey and MS_ApplicationKey as noted here in the web.config https://social.msdn.microsoft.com/forums/windowsapps/en-US/23e7163b-dad5-46ae-bf9b-c71ab067e535/microsoftwindowsazuremobileservicesmobileserviceinvalidoperationexception-the-request-could-not?forum=wpdevelop
And have also added the MS_AadClientID and MS_AadTenants key to the appSettings in the web.config also.
I am able to visit http://localhost/MobileService/help and enter the application key for the password and access the help there.
On iOS though, I am authenticating the with ADALiOS library which succeeds with authentication and returns a valid access token for the resource. Although on passing it to the mobile service I get a 401 unauthorised response which I am assuming is due to the application key somehow. With the result I am passing it to the mobile services client as so.
let payload = ["access_token": result.accessToken]
client.loginWithProvider("aad", token: payload) { user, error in
}
Any ideas or suggestions on what is missing and why it is still returning a 401 status from this login call?
EDIT:
The request headers are:
Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
"User-Agent" = "ZUMO/2.0 (lang=objective-c; os=--; os_version=--; arch=iOSSimulator; version=2.0.0.0)";
"X-ZUMO-APPLICATION" = <actual application key here>;
"X-ZUMO-INSTALLATION-ID" = "DB14CBCD-98EA-4014-AD6E-62E0CF02A9D0";
"X-ZUMO-VERSION" = "ZUMO/2.0 (lang=objective-c; os=--; os_version=--; arch=iOSSimulator; version=2.0.0.0)";
The response I get back is:
<NSHTTPURLResponse: 0x7fa882f81240> { URL: http://localhost/MobileService/login/aad } { status code: 401, headers {
"Content-Length" = 0;
Date = "Sun, 09 Nov 2014 22:39:16 GMT";
Server = "Microsoft-IIS/8.0";
"Www-Authenticate" = "Basic realm=\"Service\"";
"X-Powered-By" = "ASP.NET";
} }
EDIT:
Also doing a POST from Fiddler to the login/aad endpoint responds instantly with a 401 response, even having the app key or master key in the header and with or without the access_token body
The problem was in the configuration in web.config. The only way I found this was redoing everything and then diffing the changes
My problem was a trailing space in the value for the key MS_AadAudience key.

Json Parsing from NSURLResponse in IOS

I am getting response
<NSHTTPURLResponse: 0xa151d20> { URL: http://abcdxyz/api } { status code: 200, headers {
"Content-Length" = 0;
"Content-Type" = "text/html;charset=UTF-8";
Date = "Tue, 11 Nov 2014 06:57:01 GMT";
Server = "Apache-Coyote/1.1";
} }
Now Can u guys please help me hw will i get JSON Object from this Response. Thanks.
Your code looks good to me (except that you're making a synchronous request, but that's beside the point here.) You're getting the status code 200, which means your request was successful. If you didn't get the data you expected in the response, you'll need to check the documentation for this API to see what the expected response should be. It could be that the server returns just a simple "OK" -- which is pretty much what you're getting.
If the docs don't answer your question, try to ask someone who knows about this particular web service.

AFNetworking 2 - No response body when request fails

I am using AFNetworking 2 for an iOS project consuming a REST API. When requests fail, I am not able to get the body response.
I have seen this SO answer that says it can be retrieved from the userInfo dictionary. Unfortunately in my case I am not getting the NSLocalizedRecoverySuggestion key-value in my userInfo dictionary with the response body. Instead I see a AFNetworkingOperationFailingURLResponseErrorKey key.
My NSError log is
Error Domain=AFNetworkingErrorDomain Code=-1011 "Request failed: bad request (400)" UserInfo=0xbe471a0 {NSErrorFailingURLKey=http://***.com/api/users, AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0xbc60e80> { URL: http://***.com/api/users } { status code: 400, headers {
Connection = "keep-alive";
"Content-Length" = 85;
"Content-Type" = "application/json; charset=utf-8";
Date = "Thu, 24 Apr 2014 21:36:57 GMT";
"X-Powered-By" = Express;
} }, NSLocalizedDescription=Request failed: bad request (400)}
As you can see from the headers, I am getting "Content-Type" = "application/json; charset=utf-8"; so this other answer doesn't apply either.
Actually the body response in Postman looks like this:
{"errorCode":100,"description":"There is already a registered user with that email."}
The backend is implemented by myself in Node + Express. I am not very experienced in backend development though, so maybe there is something I am missing or that I could change.
Does anyone know why I am not getting the response body in userInfo?
Quoting AFNetworking owner:
(...) the recommended approach is to create a custom response serializer that translates response data in failing cases into NSError objects as appropriate.
You can see this answer on another AFNetworking issue to see how to integrate it with your session manager, and this repository to see how to implement it.

Resources