-
Notifications
You must be signed in to change notification settings - Fork 569
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
BREAKING(http): clean up module #3661
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think prepending unstable_
instead of having an unstable
folder is a bit tidier. Either way, seeing the http_
prefix being dropped from these files is cool!
http/unstable/errors.ts
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How come this is part of the unstable API? I'm sure I'm missing context, but the move surprises me. We use errors in SaaSKit to handle serving error responses in the REST API by throwing these HTTP errors (https://github.com/denoland/saaskit/blob/main/plugins/error_handling.ts).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my view, representing http errors as JS Error objects is an opinionated approach.
In most cases when you throw http error in your route handler or middleware, you can also directly return Response
object with error status code.
For example, the below code:
throw createHttpError(status, message)
can usually be replaced by
return new Response(message, { status });
or similar. If this replacement can be applied universally, then HttpError abstraction might be just redundant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a request handler has a call stack size of n
, using returns and finally returning an error response may require up to n
conditionals. An error needs to be handled once to return an error response. I previously used the former method in SaaSKit before realising it could be done much easier once I discovered the HTTP error code in the Standard Library. It certainly made things easier to deal with.
To be clear, if we decide that HTTP errors should be unstable, fair enough. I just wanted to provide a valid counterargument.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That might be a valid use case. Let's keep the discussion in an independent issue
Might be a good idea. @lino-levan What do you think? BTW we already have |
I think we're at least a little committed to the |
Gentle ping, @lino-levan. |
I have some concerns. Following up on discord. |
This should be ready to be merged now. Please review again, when you both get the chance. |
Looks good to me. Thanks for your contribution! @lino-levan Let's land when Asher's point is addressed. |
I believe this is ready to be merged. Please review. I would like a second pair of eyes to see if I re-exported everything properly. |
It looks like the below structure doesn't work for deprecating re-export. /** @deprecated */
export { foo } from ".."; Instead, we need to create aliases and deprecate them. import { foo as foo_ } from "..";
/** @deprecated */
export const foo = foo_; I'll make these changes in this branch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thank you for your contribution!
Thanks for the final push @kt3k! Good to know what the proper reexport structure is. |
We should check whether other deprecated sub-modules have included the correct deprecation JSDocs. |
Closes #3655 and closes #3646