Challenge: REST Advanced Operations and Error Management
Test your understanding of custom error handling and repository customization in Spring Boot by enhancing an existing e-commerce ebook store application.
We'll cover the following
Problem statement
We have an existing e-commerce application that manages ebook data using Spring Boot. Currently, the application lacks proper error handling, leading to 500 Internal Server Error
responses for common issues such as “Ebook Not Found.” To improve the application's robustness, we need to implement custom error handling to provide meaningful error responses. Additionally, the application requires a custom repository class for handling special requests such as updating frequently changing fields like the price
of an Ebook
.
Requirements
You required to implement the following:
A custom exception handling class
EbookNotFoundException
to handle cases where anEbook
is not found.A controller advice class
EbookControllerAdviser
to handleEbookNotFoundException
and other exceptions such asMethodNotAllowed
.
An EbookErrorResponse
class is provided to structure the error response with fields: timestamp
, statusCode
, path
, and message
.
A custom repository interface
CustomEbookRepository
to handle specific operations such as updating the price or other frequently changing fields of anEbook
.Ensure the custom repository is properly integrated with the existing
EbookRepository
.
Note: Ensure data integrity and maintain the current functionality throughout the implementation to prevent disruptions to the original application.
Try it yourself
Implement the missing parts in the code given below and ensure that the application correctly handles custom error responses and supports special request handling through the custom repository.
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.