Aws-sdk-ios: How can we get response HTTP status code from generated Swift iOS SDK during a error.

Created on 4 May 2017  Â·  8Comments  Â·  Source: aws-amplify/aws-sdk-ios

We are using AWSAPIGateway(v2.5.3)'s generated Swift SDK.
Generated SDK has MyDemoClient which is subclass of AWSAPIGatewayClient.

In case of success we may get model and internally may have some success httpStatusCode (2xx), but in case of error we got Error (*casting as NSError). We may get some hints using NSError.userInfo["HTTPBody”], but httpStatusCode is missing there.

How can we get response HTTP status code from generated iOS SDK during a error? In case of failure we are expecting httpStatusCode codes 4xx,5xx etc using generated SDK.

  • What service are you using?

    Using AWSAPIGateway/AWSCore modules for iOS SDK using Cocoapods Swift project

  • In what version of SDK are you facing the problem?

    2.5.3

    'AWSAPIGateway', '~> 2.5.3'

  • Is the issue limited to Simulators / Actual Devices?

    Simulator/Device


  • Can your problem be resolved if you bump to a higher version of SDK?

    Unsure, but tried 2.5.3.

  • Is this problem related to specific iOS version?

    No.
  • How are you consuming the SDK? CocoaPods / Carthage / Prebuilt frameworks?
Using Cocoapods

  • Can you give us steps to reproduce with a minimal, complete, and verifiable example? Please include any specific network conditions that might be required to reproduce the problem.

  • Generated SDK has MyDemoClient which is subclass of AWSAPIGatewayClient.

Following is observation

In following method - maps httpStatus code to client/server error codes -

- (AWSTask *)invokeHTTPRequest:(NSString *)HTTPMethod
                     URLString:(NSString *)URLString
                pathParameters:(NSDictionary *)pathParameters
               queryParameters:(NSDictionary *)queryParameters
              headerParameters:(NSDictionary *)headerParameters
                          body:(id)body
                 responseClass:(Class)responseClass {
_// Code snippets_ - 
NSHTTPURLResponse *HTTPResponse = (NSHTTPURLResponse *)response;

            NSDictionary *HTTPHeaderFields = HTTPResponse.allHeaderFields;
            NSInteger HTTPStatusCode = HTTPResponse.statusCode;
            if (HTTPStatusCode/100 == 4 || HTTPStatusCode/100 == 5) {
                NSMutableDictionary *userInfo = [NSMutableDictionary new];
                if (JSONObject) {
                    userInfo[AWSAPIGatewayErrorHTTPBodyKey] = JSONObject;
                }
                if (HTTPHeaderFields) {
                    userInfo[AWSAPIGatewayErrorHTTPHeaderFieldsKey] = HTTPHeaderFields;
                }

                if (HTTPStatusCode/100 == 4) {
                    NSError *clientError = [NSError errorWithDomain:AWSAPIGatewayErrorDomain
                                                               code:AWSAPIGatewayErrorTypeClient
                                                           userInfo:userInfo];
                    [completionSource setError:clientError];
                }
                if (HTTPStatusCode/100 == 5) {
                    NSError *clientError = [NSError errorWithDomain:AWSAPIGatewayErrorDomain
                                                               code:AWSAPIGatewayErrorTypeService
                                                           userInfo:userInfo];
                    [completionSource setError:clientError];
                }
                return;

api gateway feature request

All 8 comments

Currently you cannot get the status code of the response from the above specified method. You could alternatively use the invoke method defined here
https://github.com/aws/aws-sdk-ios/blob/master/AWSAPIGateway/AWSAPIGatewayClient.h#L50
with your generated client to get raw URL response which has the status code as well.

I will take the task of adding status code to error user info as a feature request to the team.

Thanks,
Rohan

any news about this? would be useful

gabrielkaputa, it looks like error.code has been added, however I do not see a way to see the HTTP status code in the AWSTask result, this is probably because if an error doesn't exist, the code should be HTTP 200 OK.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

This issue has been automatically closed because of inactivity. Please open a new issue if are still encountering problems.

Any update about this? I want to get http response back from invokeHTTPRequest, but I'm not finding option to do so. The error code that I get back is not https status code.

Reopening the issue per request in #1148

tweaking around NSError userInfo HTTPBody to get the returned message is really not fun... Return code support would be very handy

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ChrisInspect picture ChrisInspect  Â·  4Comments

aymericio picture aymericio  Â·  5Comments

bradgmueller picture bradgmueller  Â·  5Comments

dougboberg picture dougboberg  Â·  5Comments

pawlowskialex picture pawlowskialex  Â·  4Comments