osmlab / to-fix-backend

The to-fix server
BSD 3-Clause "New" or "Revised" License
15 stars 13 forks source link

Raise ValidationError and not 500 if item POST violates unique constraint #177

Closed batpad closed 6 years ago

batpad commented 6 years ago

We should give a better error message if the user tries to POST an item to a project with the same id as already exists - server currently returns a 500.

cc @emilymdubois

batpad commented 6 years ago

We should encapsulate this ticket into a general pattern to do better error handling.

These are docs for the error classes that Sequelize raises: https://sequelize.readthedocs.io/en/latest/api/sequelize/#error

I imagine we'd want to check in our catch code if the error raised is an instanceOf expected error classes in that list and then raise an appropriate error with appropriate status code, and if not, let it fallback to a 500 which should ideally then raise some sort of alarm so we can see what went wrong / how we got an unexpected error.