'What is the return format for AWS Swift Lambda's that execute the callback with `.failure(Error)`
Swift Lambda's can respond to requests by adopting LambdaHandler. To do so the following method must be implemented:
public func handle(context: Lambda.Context, event: APIGateway.V2.Request, callback: @escaping (Result<APIGateway.V2.Response, Error>) -> Void)
The idea is that — with successful requests — you'd return a successful response by executing the closure parameter passing a .success(APIGateway.V2.Response); and in that case it's clear what the body of the response would be — as well as the response code — as you specify them explicitly in the APIGateway.V2.Response initializer.
My question is: What is the body of the response when you pass a .failure(Error) to the given closure?
If a web service experiences an error that prevents it from returning a response in a controlled fashion that's one thing, but it's not uncommon for an application-specific error to occur that should be specified to the consumer of the service. But because there is no explicit way to specify what the body should be in the event of a unsuccessful request, it's ambiguous as to how that should be done.
Should the given Error's errorDescription property be the body of the response?
Should we be executing the closure with a value of .success in this case — despite not being successful — and passing an APIGateway.V2.Response object with an appropriate response code and the body we're intending?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
