Populating java error in postman response

  Kiến thức lập trình

am working on a spring-boot project and am trying to send a custom error in postman body that will look something like this.

{
  status:404,
  message:"No Question Found."
}

In my service class I have implemented this code and I want to send the error.

if (outputDTOSet.size() != 0) {
        } else {
            throw new BusinessException(Response.Status.NOT_FOUND,"No Question Found");
        }

But in the console am getting error.

[Request processing failed: java.lang.RuntimeException: java.lang.ClassNotFoundException: org.glassfish.jersey.internal.RuntimeDelegateImpl] with root cause

BusinessException class

public class BusinessException extends WebApplicationException {
    public BusinessException(Response.Status status, String errorMessage){
        super(Response.status(status)
                .entity(new ErrorResponse(status.getStatusCode(), errorMessage)).type(MediaType.APPLICATION_JSON).build());
    }
}

ErrorResponse.java class

@Data
@AllArgsConstructor
public class ErrorResponse {
    private int status;
    private String errorMessage;
}

Please help.

LEAVE A COMMENT