Skip to content

Commit

Permalink
fix: improve res error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
willfarrell committed May 15, 2018
1 parent 0dd33c2 commit bf336e5
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,6 @@ const jsonschemaErrors = handler => {
}

const unhandledError = handler => {
if (!(handler.error instanceof Error)) return {}
console.error(handler.context.awsRequestId, handler.error)

handler.response.statusCode = 500
handler.response.body = Object.assign({}, handler.response.body, {
errors: [
Expand All @@ -102,6 +99,7 @@ const unhandledError = handler => {
}
]
})
return handler.response
}

const linkUrl = handler => {
Expand Down Expand Up @@ -294,9 +292,9 @@ const response = (opts, handler, next) => {
handler.response = Object.assign(
{},
handler.response,
unhandledError(handler),
httpError(handler),
jsonschemaErrors(handler),
unhandledError(handler)
jsonschemaErrors(handler)
)

return next()
Expand Down

0 comments on commit bf336e5

Please sign in to comment.