Skip to content

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

Open
@nulltoken

Description

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions