error message format 변경 - OAuth2 RFC 6749
This commit is contained in:
+3
-3
@@ -5,7 +5,7 @@
|
||||
### 목표
|
||||
모든 HTTP 에러 응답을 다음과 같은 표준 JSON 포맷으로 통일:
|
||||
```json
|
||||
{"error":{"code":"에러코드","message":"에러메시지"}}
|
||||
{"error":"에러코드","error_description":"에러메시지"}
|
||||
```
|
||||
|
||||
## 변경 내역
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
- 표준 에러 응답 포맷 정의
|
||||
```java
|
||||
public static final String ERROR_MESSAGE_DEFAULT_FORMAT = "{\"error\":{\"code\":\"%s\",\"message\":\"%s\"}}";
|
||||
public static final String ERROR_MESSAGE_DEFAULT_FORMAT = "{\"error\":\"%s\",\"error_description\":\"%s\"}";
|
||||
```
|
||||
|
||||
- 에러 코드 상수 추가
|
||||
@@ -197,7 +197,7 @@ out.println(jsonErrorMessage);
|
||||
|
||||
**검증 항목**:
|
||||
- HTTP 상태 코드 정확성
|
||||
- 응답 포맷이 `{"error":{"code":"...","message":"..."}}` 형식인지 확인
|
||||
- 응답 포맷이 `{"error":"...","error_description":"..."}` 형식인지 확인
|
||||
- 에러 코드가 적절히 매핑되는지 확인
|
||||
|
||||
## 에러 코드 매핑
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
**에러 응답 포맷**:
|
||||
```json
|
||||
{"error":{"code":"에러코드","message":"에러메시지"}}
|
||||
{"error":"에러코드","error_description":"에러메시지"}
|
||||
```
|
||||
|
||||
## 테스트 케이스
|
||||
|
||||
@@ -8,7 +8,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
/**
|
||||
* MessageUtil.makeJsonErrorMessage 기본 포맷 검증 유틸리티
|
||||
* 기본 포맷: { "error" : {"code":"%s","message":"%s"} }
|
||||
* 기본 포맷: {"error":"에러코드","error_description":"에러메시지"}
|
||||
*/
|
||||
public class ErrorResponseValidator {
|
||||
|
||||
@@ -24,15 +24,10 @@ public class ErrorResponseValidator {
|
||||
assertNotNull(jsonNode, "JSON 응답이 null입니다");
|
||||
|
||||
assertTrue(jsonNode.has("error"), "error 필드가 존재해야 합니다");
|
||||
assertTrue(jsonNode.has("error_description"), "error_description 필드가 존재해야 합니다");
|
||||
|
||||
JsonNode errorNode = jsonNode.get("error");
|
||||
assertNotNull(errorNode, "error 객체가 null입니다");
|
||||
|
||||
assertTrue(errorNode.has("code"), "error.code 필드가 존재해야 합니다");
|
||||
assertTrue(errorNode.has("message"), "error.message 필드가 존재해야 합니다");
|
||||
|
||||
assertNotNull(errorNode.get("code").asText(), "error.code 값이 null입니다");
|
||||
assertNotNull(errorNode.get("message").asText(), "error.message 값이 null입니다");
|
||||
assertNotNull(jsonNode.get("error").asText(), "error 값이 null입니다");
|
||||
assertNotNull(jsonNode.get("error_description").asText(), "error_description 값이 null입니다");
|
||||
|
||||
// 검증 성공 시 Pretty Print
|
||||
String prettyJson = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonNode);
|
||||
|
||||
Reference in New Issue
Block a user