Saasli / saasli-backend

Documentation
https://saasli.github.io/docs/
0 stars 0 forks source link

Properly Formatted API Responses #40

Open godd9170 opened 7 years ago

godd9170 commented 7 years ago

I really like that python exceptions bubble up to the response, and offer the requester a meaningful response. I also really like that Regex can sniff out the response type we note in the error message. I just really hate that the stack trace is included in there.

S'far as I can tell, there's two good ways of formatting errors.

1) Response Templates

Introduce custom request bodies for each of the status codes. You can get at just the error message with a Response template of the format:

#set($inputRoot = $input.path('$'))
{
  "message" : "$input.body('$')"
}

You've got to manually create this through the AWS console for each endpoint, for each of the 8 response codes. To make it worse, running a sls deploy completely erases them. So unfortunately until serverless supports custom response body templates, this doesn't make any sense. They are so close to being done though -> https://github.com/serverless/serverless/pull/2014

2) AWS APIGW WSGI

AWS APIGW now supports custom WSGIs and this guy created a nice little pip installer to facilitate it. Concerns with this however are the inclusion of a venv in the api service. It's obviously not impossible, but it sucks to carry all that weight along for the deploy.

Conclusion

Having the stack trace come through isn't the end of the world, and I'm pretty biased to option 1) so I think we'll put a lid on this until the serverless team merges in pull #2014.

godd9170 commented 7 years ago

One in the bucket for the WSGI. http://flask.pocoo.org/docs/0.11/patterns/apierrors/

Might make all our hard work generating exceptions everywhere usable, all with the seemingly accepted strategy of WSGI.