The error handler for 404 in API blueprint is not working
mrchi opened this issue · 1 comments
Hi,
I'm reading the source code of this repository, and I noticed the error handler definitioned in director/api/__init__.py
:
@api_bp.errorhandler(404)
def not_found(error):
return jsonify({"error": error.description}), 404
But according to document of Flask
However, the blueprint cannot handle 404 routing errors because the 404 occurs at the routing level before the blueprint can be determined.
So this error handler is not working expectly. I also tried on localhost , and got default HTML reponse when visit /api/foo
.
Hi chiqj,
Indeed the blueprint error handler works for an explicit abort(404, "custom message")
:
$ curl -I http://127.0.0.1:8000/api/workflows/502d18fb-81e2-4049-a181-1505d765c00d
HTTP/1.1 404 NOT FOUND
Content-Type: application/json
...
But not for an implicit one, I just discovered that, thank you for the report 👍
The only solution I see is to handle the app exception, check the url_prefix
and returns a json response if it begins with /api
, otherwise an HTML page.