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

Replace Assertion Errors with user-friendlier http bad requests #143

Open
nulltoken opened this issue Nov 17, 2021 · 0 comments
Open

Replace Assertion Errors with user-friendlier http bad requests #143

nulltoken opened this issue Nov 17, 2021 · 0 comments
Labels
good first issue Good for newcomers

Comments

@nulltoken
Copy link
Contributor

nulltoken commented Nov 17, 2021

Following #141 (and #142), it's been put under the light that when the library is incorrectly used, it doesn't communicate the issue in a very user friendly manner

  <html lang=\"en\">
    <head>
    <meta charset=\"utf-8\">
    <title>Error</title>
    </head>
    <body>
    <pre>AssertionError [ERR_ASSERTION]: Invalid &#39;grant_type&#39; type<br> &nbsp; &nbsp;at new AssertionError (node:internal/assert/assertion_error:466:5)<br> &nbsp; &nbsp;at assertIsString (C:\\_work\\oauth2-mock-server\\src\\lib\\helpers.ts:33:11)<br> &nbsp; &nbsp;at assertIsValidTokenRequest (C:\\_work\\oauth2-mock-server\\src\\lib\\helpers.ts:64:3)<br> &nbsp; &nbsp;at fn (C:\\_work\\oauth2-mock-server\\src\\lib\\oauth2-service.ts:186:7)<br> &nbsp; &nbsp;at Layer.handle_request (C:\\_work\\oauth2-mock-server\\node_modules\\express\\lib\\router\\layer.js:95:5)<br> &nbsp; &nbsp;at next (C:\\_work\\oauth2-mock-server\\node_modules\\express\\lib\\router\\route.js:137:13)<br> &nbsp; &nbsp;at fn (C:\\_work\\oauth2-mock-server\\node_modules\\body-parser\\lib\\types\\urlencoded.js:100:7)<br> &nbsp; &nbsp;at Layer.handle_request (C:\\_work\\oauth2-mock-server\\node_modules\\express\\lib\\router\\layer.js:95:5)<br> &nbsp; &nbsp;at next (C:\\_work\\oauth2-mock-server\\node_modules\\express\\lib\\router\\route.js:137:13)<br> &nbsp; &nbsp;at Route.dispatch (C:\\_work\\oauth2-mock-server\\node_modules\\express\\lib\\router\\route.js:112:3)</pre>
    </body>
</html>

Rather than throwing AssertionErrors and letting Express default error handler deal with them, it might be cleaner to return 400 responses with a meaningful error message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant