From dd2975ba8c28fd23252f5dc2cde00411858d1429 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=B3=B4=EA=B3=A4?= Date: Wed, 18 Mar 2026 20:56:14 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20[common]=20ApiResponse=20=EC=97=90?= =?UTF-8?q?=EB=9F=AC=20=EC=8B=A0=ED=98=B8=20=EB=B0=B0=EC=97=B4=EC=9D=98=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20=ED=95=84=EB=93=9C=20=EC=A0=84=EB=8B=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - handle()에서 에러 감지 시 error/code/message/details 외 추가 필드도 전달 - error()에서 details 외 추가 필드를 error 객체에 포함 - BendingController의 expected_code 등이 API 응답에 노출됨 --- app/Helpers/ApiResponse.php | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/app/Helpers/ApiResponse.php b/app/Helpers/ApiResponse.php index b67d2b05..21c7d169 100644 --- a/app/Helpers/ApiResponse.php +++ b/app/Helpers/ApiResponse.php @@ -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'=>...] ) 하위호환