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.

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 an Ebook is not found.

  • A controller advice class EbookControllerAdviser to handle EbookNotFoundException and other exceptions such as MethodNotAllowed.

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 an Ebook.

  • 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.