Skip to content

Commit

Permalink
refactor: lambda error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mvayngrib committed Feb 13, 2018
1 parent fa39374 commit 862bf13
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,10 @@ Previous exit stack: ${this.lastExitStack}`)
this.logger.warn('likely developer error', Errors.export(err))
}

// ctx.body = this._exportError(err)
ctx.error = new Error(err.message)
if (this.source !== EventSource.HTTP) {
ctx.error = new Error(err.message)
}

this.logger.debug('lambda execution hit an error', { stack: err.stack })
} else if (result) {
ctx.body = result
Expand All @@ -334,7 +336,7 @@ Previous exit stack: ${this.lastExitStack}`)
throw new Error('lambda already exited')
}

ctx.callback(ctx.error, ctx.body)
ctx.callback(ctx.error, ctx.error ? null : ctx.body)
}

this.reset()
Expand Down Expand Up @@ -455,7 +457,11 @@ Previous exit stack: ${this.lastExitStack}`)
await next()
} catch (err) {
ctx.error = err
ctx.status = 500
if (!ctx.status || ctx.status <= 300) {
ctx.status = 500
}

ctx.body = this._exportError(ctx.error)
}
}

Expand Down

0 comments on commit 862bf13

Please sign in to comment.