How can I change error templates for API Gateway?

I’m building a serverless project using Python. API Gateway expects errors from Python code to be surfaced as exceptions. Serverless handles detection of the error code, but passes through the ugly stack trace to the user. Is there a way to override the default error template in serverless.yml?

Hey @slank have you settled on a solution for this? I’ve landed on returning custom exceptions, and too want that stack trace gone. I’ve found this PR https://github.com/serverless/serverless/pull/2014 which I think will solve what we’re after, but it’s not merged yet.

No, I didn’t find a solution. Once AWS released Simple Proxy I developed a WSGI adapter for it and never looked back.

Custom Status code will be merged soonish, but yeah going with the Proxy is definitely a good idea.

Hey @slank and @flomotlik thanks for this! I’m curious as to how you catch these errors and format their response. One thing I really liked about the original Lambda integration was that if an error raised anywhere, the error-type and message were pushed out to the requester.

The Proxy integration seems to offer only Process exited before completing request. I liked the idea of regex matching a ‘403’ for example in an error message, then formatting it with some meaning.

Thoughts?

Is it via a strategy like this? http://flask.pocoo.org/docs/0.11/patterns/apierrors/

+1
I’m interested in configure my own error responses as something more standard (and especially to avoid the stack trace).
For example:

{
 "type": "USER.NOT.FOUND", 
 "status": 404,
"message": "not found"
 }

How would the serverless.yml look when using awsgi?
Perhaps compared to https://www.npmjs.com/package/serverless-wsgi ?