BransbyHorses / equine-training-tracker-api

REST API for Bransby equine training tracker
0 stars 0 forks source link

Add a custom exception class for handling thrown errors in spring #34

Open MikeDThorpe opened 2 years ago

MikeDThorpe commented 2 years ago

https://www.toptal.com/java/spring-boot-rest-api-error-handling - reading this article it's considered best practice to offload exception handling to a global error handling class annotated with @Controlleradvice that spring uses to handle all exceptions thrown by service methods.

The article suggests controller methods should only return 'success' responses and allow all error responses (404, 500 etc.) to be handled by the global error class.

MikeDThorpe commented 2 years ago

I've branched off of PR #30 to start this ticket.

MikeDThorpe commented 2 years ago

I've reformatted the controller and service logic in the programme, yard, disruption and category routes to use the global exception handler.