Skip to content

Instantly share code, notes, and snippets.

@sungjunyoung
Last active January 25, 2017 04:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sungjunyoung/3bf676d42f0f85695612921407bb455e to your computer and use it in GitHub Desktop.
Save sungjunyoung/3bf676d42f0f85695612921407bb455e to your computer and use it in GitHub Desktop.
var errorResponse = function (statusCode, errorCode, detailMessage) {
var messageMap = {
400: 'Bad Request',
401: 'Unauthonized',
403: 'Forbidden',
404: 'Not Found',
405: 'Method Not Allowd',
406: 'Not Acceptable',
409: 'Conflict',
500: 'Internal Server Error'
};
return {
statusCode: statusCode,
body: JSON.stringify({
code: errorCode,
message: messageMap[statusCode],
detail: detailMessage
}),
headers: {
'Content-Type': 'application/json',
'X-Requested-With' : 'XMLHttpRequest',
'Access-Control-Allow-Origin' : '*'
}
}
};
@sungjunyoung
Copy link
Author

This is part of my lambda function code, Which allow return HTTP status code with message / enable CORS.
Of course you must check 'lambda proxy integration' in API-Gateway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment