Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add RequestError class #562

Closed
wants to merge 1 commit into from
Closed

Conversation

kettanaito
Copy link
Member

@kettanaito kettanaito commented Apr 21, 2024

Right now, there's no way to prevent an error from being coerces as a 500 error response. In some cases, like here, we do want to throw an error for it to error the request instead of producing an error response.

This adds a new RequestError class. If an instance of RequestError is thrown within a request listener, the respective request will error with the error thrown.

Behavior-wise, this is similar to using Response.error() as a mocked response. The difference is that you can throw RequestError anywhere in the request handling pipeline.

Now, to think of it, we can achieve the same behavior by throw Response.error(). Right now, though, that won't work because a thrown Response is always forwarded to .respondWith() as-is, which is incorrect in the case of Response.error(). In other words, we are only handling Response.error() if it's provided to request.respondWith(), not thrown.

@kettanaito kettanaito changed the title fix: add RequestError class fix: add RequestError class Apr 21, 2024
@kettanaito kettanaito marked this pull request as draft April 21, 2024 09:44
@kettanaito
Copy link
Member Author

This is potentially solved by adding support for throwing Response.error() (#563).

@kettanaito
Copy link
Member Author

Not needed.

#566 allows you to opt-out from the default exception handling. In the future, controller.errorWith() will allow you to mock request errors explicitly (see #431).

@kettanaito kettanaito closed this Apr 29, 2024
@kettanaito kettanaito deleted the fix/request-error-class branch April 29, 2024 13:03
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