FrancisG-Massey / Capstone2016

4 stars 0 forks source link

Improve error reporting in API responses #176

Open sam-hunt opened 7 years ago

sam-hunt commented 7 years ago

Some API failed requests have 500 Internal Server Error codes when they are in fact _400 Bad Request_s semantically.

This occurs because SQLExceptions can be db connection failures which must be 500. Except schema constraint violations (of which we have an increasing number of) are also thrown as SQLExceptions and so are caught in the same catch block.

This can be very confusing when debugging integration failures from the mobile or web app clients.

The only way to sort these is likely to be through string parsing the exception error messages. We could do this with regex in a way which could be applied across the API however, giving us a flexible way to parse errors into something the client can understand, and possibly match them with http error codes as well.

This can also be documented in the RESTful API Specification document to be very useful.

sam-hunt commented 7 years ago

Dependent on #177, as these errors could be easily defined in the config, and then uniformly checked using a defined order over each error message whenever an exception is thrown from anywhere in the API.

FrancisG-Massey commented 7 years ago

You could try using SQLException.getSQLState() to get the Postgres error codes, as suggested here: http://stackoverflow.com/questions/26383624/postgres-exceptions-and-java

sam-hunt commented 7 years ago

Ah yeah, I'll have a play around with it when #177 is done and see what is easiest. If I use regex and the SQL state is in the string (pretty sure it is) then we won't need to go that far. Using regex also means that we can use a generic exception handling function rather than a specific one for different types of exceptions (psqlexception/sqlexcetion/ioexception/etc) Also would like to keep PSQLException out of the codebase if possible as we discussed earlier.