We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hey
I'm trying to return a custom error code as shown here: https://flask-restful.readthedocs.io/en/latest/extending.html?highlight=errors#define-custom-error-messages At the bottom of at the page.
Here is a snippet from my code:
from flask import Flask, Response from flask_restful import Resource, Api, reqparse, abort class SamplesNotFound(HTTPException): pass error_dict = { "SamplesNotFound": { 'message': "No samples found for these features.", 'status': 522, } } class Index(Resource): def get(self): abort(522) app = Flask(__name__) api = Api(app, errors=errors.error_dict) api.add_resource(Index, '/index') if __name__ == '__main__': app.run(host='0.0.0.0', port=5000, debug=False)
I get a 500 error code on the response instead of 522. + I want to get a json in the response and I get a string.
Please help
Best, Roy
The text was updated successfully, but these errors were encountered:
Use raise SamplesNotFound() in place of abort(522).
raise SamplesNotFound()
abort(522)
P.S. Make sure you're passing errors_dict to the Api constructor. Your snippet has it written as errors.error_dict, which doesn't exist.
errors_dict
errors.error_dict
Sorry, something went wrong.
No branches or pull requests
Hey
I'm trying to return a custom error code as shown here:
https://flask-restful.readthedocs.io/en/latest/extending.html?highlight=errors#define-custom-error-messages
At the bottom of at the page.
Here is a snippet from my code:
I get a 500 error code on the response instead of 522.
+
I want to get a json in the response and I get a string.
Please help
Best,
Roy
The text was updated successfully, but these errors were encountered: