Skip to content

Fix API Gateway error responses#187

Merged
christophgysin merged 8 commits into
serverless:masterfrom
adambrgmn:fix-apig-error-responses
Sep 15, 2017
Merged

Fix API Gateway error responses#187
christophgysin merged 8 commits into
serverless:masterfrom
adambrgmn:fix-apig-error-responses

Conversation

@adambrgmn
Copy link
Copy Markdown
Contributor

As earlier discussed in issue #186, I took the liberty of (hopefully) updating all aws-node-... examples with lamdas that responds to API Gateway-events and changed their error responses so that they respond correctly.

I also want to point out that I haven't changed the structure of the code or anything. I have only changed the original callbacks, e.g.:

if (error) {
  callback(new Error('Something went wrong'));
}

I have transformed them so that the lambdas ”don't think” that an error occured, e.g.:

if (error) {
  callback(null, {
    statusCode: error.statusCode || 501,
    headers: { 'Content-Type': 'plain/text' },
    body: error.message || 'Internal server error',
  });
}

In the first case an http request would always return a 502 Bad Gateway response. But in the latter case the response would be more correct and give useful feedback to users.

I have tried to keep the errors as close to the original as possible, and sometimes I have guessed on a suitable statusCode and message.

I hope that it is okey that I made this into a larger PR, instead of splitting it up into one PR per example.

This PR resolves #186.

@christophgysin christophgysin merged commit 991db05 into serverless:master Sep 15, 2017
@christophgysin
Copy link
Copy Markdown
Contributor

Thanks!

@adambrgmn adambrgmn deleted the fix-apig-error-responses branch September 17, 2017 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect error handling in API Gateway examples

2 participants