From the course: Advanced Spring: Effective Integration Testing with Spring Boot
Unlock the full course today
Join today to access over 22,500 courses taught by industry experts or purchase this course individually.
Testing custom exception returns
From the course: Advanced Spring: Effective Integration Testing with Spring Boot
Testing custom exception returns
- [Instructor] Spring Boot comes with some great features to help with error handling. But it is left to the developer to use those features the three the exceptions and return meaningful responses to the API client. Let's fire up our application and see how we are handling cases when somebody is looking for a research that is not found. What will happen when we try to retrieve a student that does not exist. So to do that, we need to call the following rest endpoint. Get students ID. Well, the default error representation looks a little bit messy and misleading, right? 500 is not the right code to describe that the requested resource is not found. Each should be 404. Internal server error does not provide any meaningful information to the API consumers. Exposing 500 internal server errors to the clients is not a good practice at all. So, to handle our errors properly we need to customize the default Spring Boot API error response with a meaningful message indicating what went wrong…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.