Как это сделать?
Сообщение об ошибке «Мой клиент»
Код: Выделить всё
public class ApiErrorResponse {
private int code;
private String message;
public ApiErrorResponse(int code, String message) {
this.code = code;
this.message = message;
}
public String getMessage() {
return message;
}
public int getCode() {
return code;
}
}
Код: Выделить всё
@ControllerAdvice
public class ApiExceptionHandler {
@ExceptionHandler({NoHandlerFoundException.class})
public ResponseEntity handleNoHandlerFoundException(
NoHandlerFoundException ex, HttpServletRequest httpServletRequest) {
ApiErrorResponse apiErrorResponse = new ApiErrorResponse(404, "Resource not found");
return ResponseEntity.status(HttpStatus.NOT_FOUND).contentType(MediaType.APPLICATION_JSON).body(apiErrorResponse);
}
}
Но он выдает код состояния по умолчанию 404 и сообщение об ошибке. не пользовательское сообщение . Чего мне здесь не хватает?
Подробнее здесь: https://stackoverflow.com/questions/770 ... om-message
Мобильная версия