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.
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

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;
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