3 ms·
It’s important to distinguish between validation and exception. If a client passes in bad value you can handle:, out of range, not found db item etc, return an
by shireboy 4y ago
It’s important to distinguish between validation and exception. If a client passes in bad value you can handle:, out of range, not found db item etc, return an appropriate 400 with details about the error that the client can do something with. Handle it gracefully if you can without throwing exception.
If it’s something impossible to handle - say a db failure after n retries- then return a 500 with some info but not anything sensitive. No db names, queries, etc.
Sometimes your exceptions tell you about additional validation you need to add. Ie users keep passing in invalid ids and I get a db exception, maybe I should instead check for the row first and return a 404.
Log all the things.
There are standards for REST error responses:
https://blog.restcase.com/rest-api-error-handling-problem-details-response/#:~:text=RFC%207807%20provides%20a%20standard%20format%20for%20returning,range%20to%20detail%20the%20general%20category%20of%20error https://blog.restcase.com/rest-api-error-handling-problem-de....