I would like to do some handler for exception. I'm using a combination of Flask-restless and SQLAlchemy in python.
My problem:
When I send request to api with object that already exists in DB, SQLAlchemy shows exception:
IntegrityError: (IntegrityError) column <column_name> is not unique u'INSERT INTO ...
So I have tried to add attribute validation_exceptions
into create_api
method:
manager.create_api( ... , validation_exceptions=[IntegrityError])
But response json contains:
{
"validation_errors": "Could not determine specific validation errors"
}
and server api shows exception :
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\flask_restless\views.py", line 797, in _extract_error_messages
left, right = str(exception).rsplit(':', 1)
ValueError: need more than 1 value to unpack
Exception validation in Flask-restless doesn't work with this type of exception (IntegrityError)
What should I do? Is it possible to create some handler for exception and to return my own error message in json?