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

Crashed my express server. #136

Open
4 tasks done
DavidWalley opened this issue Feb 1, 2024 · 2 comments
Open
4 tasks done

Crashed my express server. #136

DavidWalley opened this issue Feb 1, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@DavidWalley
Copy link

Checklist

  • I have looked into the Readme and Examples, and have not found a suitable solution or answer.
  • I have searched the issues and have not found a suitable solution or answer.
  • I have searched the Auth0 Community forums and have not found a suitable solution or answer.
  • I agree to the terms within the Auth0 Code of Conduct.

Description

I made a mistake in my client's authentication code, and it crashed my server.

Reproduction

I have been running a development express server without any problem for some time. I made an error in the client, which I have fixed. But, I was able to crash the express server. I don't want this, or any error, to crash the server, I just want an error message, or rejected request. I don't know where to start with this error:
InvalidTokenError: Invalid Compact JWS
at /home/dave/Desktop/AAA/PrizeKick/App/api3/node_modules/express-oauth2-jwt-bearer/dist/index.js:300:19
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async /home/dave/Desktop/AAA/PrizeKick/App/api3/node_modules/express-oauth2-jwt-bearer/dist/index.js:403:24

Obviously I am doing something wrong but the server crashed and I don't want someone else to crash the server.

Additional context

No response

express-oauth2-jwt-bearer version

1.6.0

Node.js version

v20.10.0

@DavidWalley DavidWalley added the bug Something isn't working label Feb 1, 2024
@carluis321
Copy link

@DavidWalley did you create the middleware for catching errors?

@ehaynes99
Copy link

There's nothing particularly unique about this middleware vs others. You should always have a global "catch all" error handler attached to your app AFTER all other routes and middleware. Note that express looks at the number of arguments to determine if a handler is an error handler or not, so even if unused, it has to have 4.

const errorHandler: ErrorRequestHandler = (err, req, res, _next) => {
  console.error('Unhandled error during request', err)
  res.set('Content-Type', 'application/json').status(500).json({ error: err.message })
}

// very last `use`
app.use(errorHandler)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants