Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions packages/express-wrapper/src/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,12 @@ export const defaultResponseEncoder: ResponseEncoder = (
return;
}
const responseCodec = route.response[status];
if (responseCodec === undefined || !responseCodec.is(payload)) {
try {
expressRes.status(status).json(responseCodec!.encode(payload)).end();
} catch {
console.warn(
"Unable to encode route's return value, did you return the expected type?",
);
expressRes.status(500).end();
return;
}

expressRes.status(status).json(responseCodec.encode(payload)).end();
};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Proving that responseCodec isn't undefined is pretty gross in this implementation 😓 I used a ! because undefined has no encode method will still jump to the catch block