httpland/http-router

routers should not throw errors

TomokiMiyauci opened this issue ยท 3 comments

Throwing errors destroys the system.

Instead of throwing errors, here are some ways to express errors:

  • Union of type null
  • Union of error types
  • Result Monad

Neither of these is appropriate.

For example, a result monad might look like this:

const handler = URLRouter({
  "/": MethodRouter({
    GET: () => new Response(),
  }).mapErr(reportError).unwrap(),

  "/api": MethodRouter({
    POST: () => new Response(),
  }).mapErr(reportError).unwrap(),
}).mapErr(reportError).unwrap();

This is terrible.

To begin with, this project is intended to allow routes to be written in an aggregate, complete manner.

Any other proposal would make routes difficult to read, requiring optional operators, etc.

Proposal

This proposal solves this by delegating error checking to another function.
The router will just ignore the route, even if there is an error in the route.
The router will just return a handler, silently rejecting all errors.

Instead, it provides an assert function to verify the error.

The user can choose to use the assert function.

๐ŸŽ‰ This issue has been resolved in version 2.0.0-beta.3 ๐ŸŽ‰

The release is available on GitHub release

Your semantic-release bot ๐Ÿ“ฆ๐Ÿš€

๐ŸŽ‰ This issue has been resolved in version 2.0.0 ๐ŸŽ‰

The release is available on GitHub release

Your semantic-release bot ๐Ÿ“ฆ๐Ÿš€

๐ŸŽ‰ This issue has been resolved in version 1.0.0-beta.6 ๐ŸŽ‰

The release is available on GitHub release

Your semantic-release bot ๐Ÿ“ฆ๐Ÿš€