ColtonProvias / sqlalchemy-jsonapi

JSONAPI implementation for use with SQLAlchemy
MIT License
70 stars 27 forks source link

Raise ValidationError with str(e) rather than e.msg #39

Closed kaitj91 closed 7 years ago

kaitj91 commented 7 years ago

In patch_resource and post_collection we were excepting an AssertionError and then raising a custom ValidationError from the errors.py file. For example,

        except AssertionError as e:
            session.rollback()
            raise ValidationError(e.msg)

The problem is that there is no msg attribute on the exception.

While I tried to change this to be ValidationError(e) instead, this raises a TypeError in the json.JSONEncoder since the AssertionError is not JSON serializable.

Thus the easiest option that also keeps our tests passing is to do it as such

        except AssertionError as e:
            session.rollback()
            raise ValidationError(str(e))
Anderycks commented 7 years ago

We shouldn't cast to string here. We should handle that in the encoder. Encoding is in the name for "JSONEncoder." 😄

Grab me at work today and we can discuss this further.

kaitj91 commented 7 years ago

Will fix differently later.