is there any implementation exists on JSON as custom error page on Flask?
You can create a json response object using the "jsonify" helper from flask and then set the status_code of the response before returning it like this:
def not_found(error):
response = jsonify({'code': 404,'message': 'No interface defined for URL'})
response.status_code = 404
return response
You can register this function as the handler by wrapping it in the errorhandler:
@app.errorhandler(404)
def not_found(error):
...
OR, setting it directly on the error_handler_spec:
app.error_handler_spec[None][404] = not_found
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With