Customizing the exception message

Let's look at how to customize the preceding exception and return the proper response status with a customized message.

Let's create a bean to define the structure of our custom exception message:

    public class ExceptionResponse {      private Date timestamp = new Date();      private String message;      private String details;      public ExceptionResponse(String message, String details) {        super();        this.message = message;        this.details = details;       }      public Date getTimestamp() {        return timestamp;      }      public String getMessage() {        return message;      }      public String getDetails() {        return details;      }     }

We have created a simple exception response bean with an auto-populated timestamp with a few additional properties namely messages and ...

Get Mastering Spring 5.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.