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

Allow to use custom error codes for unexpected errors #375

Open
Talkless opened this issue Mar 10, 2023 · 1 comment
Open

Allow to use custom error codes for unexpected errors #375

Talkless opened this issue Mar 10, 2023 · 1 comment

Comments

@Talkless
Copy link

Any unexpected error is translated to ServerError with default error code:

jsonrpc_error = ServerError(data={'message': str(e)})

It would be useful to convert, for example, JWTError (https://github.com/mattupstate/flask-jwt/blob/c27084114e258863b82753fc574a362cd6c62fcd/flask_jwt/__init__.py#L160) to ServerError with specific error code for easier and more deterministic (avoiding string comparison) error handling in frontend.

Changing

jsonrpc_error = ServerError(data={'message': str(e)})

into something similar to:

jsonrpc_error = self.make_unexpected_error(e)

could maybe work, if we then could specify custom handler for unexpected errors.

@nycholas
Copy link
Member

Maybe here, instead of creating an error handling by scratch, uses the Flask Error Handling: https://flask.palletsprojects.com/en/2.2.x/errorhandling/#error-handlers

I will check out how to use that, ;).

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

No branches or pull requests

2 participants