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

Incorrect type definitions and switched variable for errorHandler #29

Open
MikkelSVDK opened this issue Sep 21, 2023 · 0 comments
Open

Comments

@MikkelSVDK
Copy link

In this example the middleware is "wrongly" classed as a Handler and not a MiddlewareFunc

(method) BunServer.use(middleware: Handler): void
app.use((req: BunRequest, res: BunResponse, next: ((err?: Error | undefined) => {}) | undefined) => {
  console.log("middlewares called");
  next!(); // Results in next() possible undefined
})

What it should classify it as src/server/request.ts

11 export type MiddlewareFunc = (
12   req: Request,
13   res: BunResponse,
14   next: (err?: Error) => {}
15 ) => void;

The errorhandler in src/server/server.ts also switches the err and next function around based on the type definitions from src/server/request.ts

4 export type Handler = (
5   req: BunRequest,
6   res: BunResponse,
7   next?: (err?: Error) => {},
8   err?: Error
9 ) => void | Promise<any>;

src/server/server.ts

229 that.errorHandlers.forEach((handler) => {
230   // * no request object pass to error handler
231   handler.apply(that, [null, res, err, next]);
232 });
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

No branches or pull requests

1 participant