Flask-jwt and Flask-resftul error handling Flask-jwt and Flask-resftul error handling flask flask

Flask-jwt and Flask-resftul error handling


I see that you are trying to raise an HTTPException from these errors, which helps with returning them to users. To raise an HTTP exception, you can catch all errors and if they are an instance of a JWTError, you can convert them to an instance of an HTTPException using a function like the following:

def convert_to_http_exception(e):    if isinstance(e, JWTError):        jwtdescription = e.error + ": " + e.description        http_exception = HTTPException(description=jwtdescription)        http_exception.code = e.status_code        return http_exception    else:        return e