Error Handling
Table of contents
Kind of handlers
JWT.handler
has these handlers:
Name | Exception to handle |
---|---|
no_authorization | NoAuthorizationError |
expired_signature | ExpiredSignatureError |
invalid_header | InvalidHeaderError |
invalid_token | InvalidTokenError |
jwt_decode_error | JWTDecodeError |
wrong_token | WrongTokenError |
revoked_token | RevokedTokenError |
fresh_token_required | FreshTokenRequiredError |
access_denied | AccessDeniedError |
Change behavior of handler
First, you need to make function with this signature
async def my_handler(request: sanic.request.Request, exception: JWTExtendedException) -> sanic.response.HTTPResponse:
...
Then assign function to handler you want to modify while initializing JWT
with JWT.initialize(app) as manager:
manager.handler.no_authorization = my_handler