Strange behavior when call is made from ajax, other domain
See original GitHub issueHi! I have a project where front-end(React) and back-end(Flask) are working on different domains.
I added the following test end-point:
@test _api.route('/test')
class test_route(Resource):
@jwt_required
def get(self):
return jsonify({'result': True})
It’s working properly if I provide a valid access token (in header, as I can’t use it in the cookie).
But if it’s not provided, or it’s wrong I can’t make the following handler work right:
@jwt.unauthorized_loader
def unauthorized_loader_handler(message):
return jsonify({
"description": "Access token not found!",
"error": "unauthorized_loader"
}, 401)
in a case of unauthorized loader and get into this handler but right after the exception is thrown:
Server-side ERROR: ‘Response’ object has no attribute ‘get’
I just want it to return status 401 to the front-end.
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (3 by maintainers)
Top Results From Across the Web
Different behaviour in AJAX call in browser and "Copy as cURL"
This AJAX call shows a super strange behaviour: When initiated by the browser through the page's JavaScript, the call doesn't work as expected....
Read more >Strange behavior with ajax requests (CORS problem) - General
This domain is behind Cloudflare and the web page simply make 2 POST Ajax calls to 2 differents subdomains. First one : https://demo1.rpgmax.fr/...
Read more >Using CORS for Cross-Domain Ajax Requests
If the script on your page is running from domain mydomain.com and would like to request a resource via an XmlHttpRequest or XDomainRequst...
Read more >My head hurts ~ DataTables with Cross Domain Ajax Request
I understand that json through AJAX over cross domain doesn't work without altering the code but, I am apparently missing something.
Read more >Solutions to 5 Common Ajax Problems - Webdesigner Depot
This problem occurs when a designer has incorporated JavaScript and Ajax enhancements into their website's architecture without making ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
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
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

This is one of the options that should work with Flask-restx.
_set_error_handler_callbacks(api).Example
Thanks @0xbart !
While upgrading my app and moving from flask_restplus to flask_restx the option 1 (which was working with flask_restplus) was only working when running tox to test the app, but not when running the server for some reason.
The option 2 did the trick for me on both. Much appreciated!