Skip to content

Commit

Permalink
fix(app): make sure resolved val is also not undefined before calling…
Browse files Browse the repository at this point in the history
… hooks
  • Loading branch information
pi0 committed Aug 2, 2023
1 parent c266755 commit cfe397e
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,9 @@ export function createAppEventHandler(stack: Stack, options: AppOptions) {
const val = await layer.handler(event);

// 5. Try to handle return value
const _response = val === undefined ? undefined : { body: await val };
if (_response !== undefined) {
const _body = val === undefined ? undefined : await val;
if (_body !== undefined) {
const _response = { body: _body };
if (options.onBeforeResponse) {
await options.onBeforeResponse(event, _response);
}
Expand All @@ -166,7 +167,7 @@ export function createAppEventHandler(stack: Stack, options: AppOptions) {
// Already handled
if (event.handled) {
if (options.onAfterResponse) {
await options.onAfterResponse(event, _response);
await options.onAfterResponse(event, undefined);
}
return;
}
Expand Down

0 comments on commit cfe397e

Please sign in to comment.