Errors (i.e. 401) not returned
See original GitHub issueIt looks to me that this part is not yet implemented:
def jwt_required(fn):
    @wraps(fn)
    def wrapper(*args, **kwargs):
        jwt_data = _decode_jwt_from_request(request_type='access')
        ctx_stack.top.jwt = jwt_data
        _load_user(jwt_data[config.identity_claim])
        return fn(*args, **kwargs)
    return wrapper
The upper code raises many different exceptions, but I don’t see any code returning the errors (my own default error handling of restplus triggers 500 error every time).
The documentation states that:
If the access token is not valid for any reason (missing, expired, tampered with, etc) we will return json in the format of {‘msg’: ‘why accessing endpoint failed’} along with an appropriate http status code (generally 401 or 422).
Default callbacks are all provided, but never returned.
Am I wrong?
Thanks, Meir Tseitlin
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:32 (15 by maintainers)
 Top Results From Across the Web
Top Results From Across the Web
How to Quickly Fix the 401 Unauthorized Error (5 Methods)
The 401 (Unauthorized) status code indicates that the request has not been applied because it lacks valid authentication credentials for the ...
Read more >401 Unauthorized Error: What It Is and How to Fix It
The 401 Unauthorized Error is an HTTP response status code indicating that the client could not authenticate a request.
Read more >How to Fix a 401 Unauthorized Error - Lifewire
The 401 Unauthorized error is an HTTP status code that means the page you were trying to access cannot be loaded until you...
Read more >A Useful Guide to Diagnosing and Solving the 401 Error
You will get the error when entering the wrong credentials or not entering them to access a password-protected web page. The main message...
Read more >How to Fix a 401 Unauthorized Error? - GeeksforGeeks
It may be represented as 401 Unauthorized, Authorization required, HTTP error 401- Unauthorized. It represents that the request could not be ...
Read more > Top Related Medium Post
Top Related Medium Post
No results found
 Top Related StackOverflow Question
Top Related StackOverflow Question
 Troubleshoot Live Code
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free Top Related Reddit Thread
Top Related Reddit Thread
 Top Related Hackernoon Post
Top Related Hackernoon Post
No results found
 Top Related Tweet
Top Related Tweet
No results found
 Top Related Dev.to Post
Top Related Dev.to Post
No results found
 Top Related Hashnode Post
Top Related Hashnode Post
No results found

I’ve thought of a better way to solve this. It is very much a hack, and I still think flask-restplus should fix their extension so that it does not break native flask features, but it should get you up and going safer then how you have it handled above.
It looks like the errorhandler method for restplus uses the same signature that flask error handler does, so you could take advantage of duck typing and access this internal method to set the errors on the restplus level: https://github.com/vimalloc/flask-jwt-extended/blob/master/flask_jwt_extended/jwt_manager.py#L81
This would obviously be prone to break if I changed how the underlying part of this extension worked, as you are accessing a private method that doesn’t have any guarantees on it, but I do not see any reason why that method would change in the foreseeable future, and this would insure that any new or changed error handles in this extension would get properly set on the flask-restplus extension.
Hope this helps 😃
Yeah, for whatever reason when you are using flask-restful you will need to set
app.config['PROPAGATE_EXCEPTIONS'] = Truein order for the error handlers to properly work. I would expect that to fix your issue.