오류 응답 Spring Boot에서 "message" 필드가 비어 있습니다.
이렇게 허가받지 않은 예외를 처리했습니다.
@ResponseStatus(value= HttpStatus.UNAUTHORIZED)
public class UnauthorizedException extends RuntimeException {
public UnauthorizedException(String message) {
super(message);
}
}
하지만 내가 다음과 같이 오류를 던지면
throw new UnauthorizedException("Invalid credentials");
다음과 같은 오류 메시지가 응답에 공백으로 표시됩니다.
{
"timestamp": "2020-05-27T13:44:58.032+00:00",
"status": 401,
"error": "Unauthorized",
"message": "",
"path": "/auth/register"
}
써봤는데
throw new ResponseStatusException(HttpStatus.UNAUTHORIZED, "Invalid credentials");
결과는 그대로입니다.spring-boot-devtools 의존관계를 추가하면 스택트레이스에서도 정상적으로 메시지가 표시됩니다.어떻게 하면 고칠 수 있을까요?
스프링 버전: 2.3.0 Java 버전: 11.0
알겠습니다. server.error.include-message의 기본값을 "never"로 변경했습니다(여기서 설명 섹션: Spring 2.3.0 릴리즈 정보 참조).
모든 기본값은 다음과 같습니다.Spring Boot Reference Documentation 。
application.yaml(또는 속성)을 다음과 같이 설정합니다.
server:
error:
include-message: always
include-binding-errors: always
오류 메시지를 표시하면 서버 구현에 대한 정보가 유출될 수 있습니다.
언급URL : https://stackoverflow.com/questions/62044747/message-field-is-empty-in-error-response-spring-boot
'programing' 카테고리의 다른 글
| Oracle의 기본 날짜 형식은 YYY-MM-DD입니다. 이유는 무엇입니까? (0) | 2023.04.04 |
|---|---|
| ng-repeat을 사용한 목록 페이지 번호 지정 (0) | 2023.04.04 |
| 각 JS 브레이크 (0) | 2023.04.04 |
| Objective-C 개체를 JSON으로 직렬화 및 직렬화 해제 (0) | 2023.04.04 |
| TypeScript를 사용한 개방형 함수 인수 (0) | 2023.03.25 |