Skip to content

fix: respond with 500 when a handler throws a non-Error value - #492

Open
RaphaelFakhri wants to merge 1 commit into
vercel:mainfrom
RaphaelFakhri:fix-run-non-error-throw
Open

RaphaelFakhri wants to merge 1 commit into
vercel:mainfrom
RaphaelFakhri:fix-run-non-error-throw

Conversation

@RaphaelFakhri

Copy link
Copy Markdown

Fixes a request that never completes when a handler throws or rejects with a value that is not an Error.

Problem

run() only answers errors that pass isError(). If a handler throws a string, a plain object, or rejects with a non-Error value, the catch branch does nothing. No response is sent and the client waits until it times out.

module.exports = () => {
  throw 'boom';
};

Changes

  • run() now always calls sendError(). A non-Error value is wrapped in an Error that includes the inspected value, so the client gets a 500 and the server logs the stack.
  • Adds two tests: a synchronous throw of a string and a Promise.reject() with a plain object.

Testing

cd test && npx tap --ts suite/

Before the change, both new tests fail with a network timeout. After the change, all three suites pass.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant