fix: [common] ApiResponse 에러 신호 배열의 추가 필드 전달
- handle()에서 에러 감지 시 error/code/message/details 외 추가 필드도 전달 - error()에서 details 외 추가 필드를 error 객체에 포함 - BendingController의 expected_code 등이 API 응답에 노출됨
This commit is contained in:
@@ -146,13 +146,22 @@ public static function error(
|
||||
int $code = 400,
|
||||
array $error = []
|
||||
): JsonResponse {
|
||||
$errorBody = [
|
||||
'code' => $code,
|
||||
'details' => $error['details'] ?? null,
|
||||
];
|
||||
|
||||
// details, code 이외 추가 필드(expected_code 등)를 error 객체에 포함
|
||||
$reserved = ['details'];
|
||||
$extra = array_diff_key($error, array_flip($reserved));
|
||||
if ($extra) {
|
||||
$errorBody = array_merge($errorBody, $extra);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => "[{$code}] {$message}",
|
||||
'error' => [
|
||||
'code' => $code,
|
||||
'details' => $error['details'] ?? null,
|
||||
],
|
||||
'error' => $errorBody,
|
||||
], $code);
|
||||
}
|
||||
|
||||
@@ -225,8 +234,16 @@ public static function handle(
|
||||
$message = (string) ($result['message'] ?? ($result['error'] ?? '서버 에러'));
|
||||
$details = $result['details'] ?? null;
|
||||
|
||||
// 에러 신호 배열의 추가 필드(expected_code 등)를 응답에 포함
|
||||
$reserved = ['error', 'code', 'message', 'details'];
|
||||
$extra = array_diff_key($result, array_flip($reserved));
|
||||
$errorData = ['details' => $details];
|
||||
if ($extra) {
|
||||
$errorData = array_merge($errorData, $extra);
|
||||
}
|
||||
|
||||
// 에러에도 쿼리 로그 포함되도록 error()가 처리하게 맡김
|
||||
return self::error($message, $code, ['details' => $details]);
|
||||
return self::error($message, $code, $errorData);
|
||||
}
|
||||
|
||||
// 표준 박스( ['data'=>..., 'query'=>..., 'statusCode'=>...] ) 하위호환
|
||||
|
||||
Reference in New Issue
Block a user