diff --git a/apps/cs/app/api/proxy/[...url]/route.ts b/apps/cs/app/api/proxy/[...url]/route.ts index 8e9a39cae..f42400d1b 100644 --- a/apps/cs/app/api/proxy/[...url]/route.ts +++ b/apps/cs/app/api/proxy/[...url]/route.ts @@ -56,10 +56,32 @@ async function handler( if (!result.ok) { console.error(`[BFF Proxy Error] Backend returned status ${result.status} for ${params.url.join("/")}`); + let errorText = ""; try { - const errorText = await result.text(); + errorText = await result.text(); console.error(`[BFF Proxy Error Body] ${errorText}`); } catch (err) {} + + if (result.status === 503) { + const serviceName = params.url[0] || "user-service"; + return NextResponse.json( + { message: `${serviceName} 서비스와의 연결이 불안정 합니다. 관리자에게 연락해 주십시오.` }, + { status: 503 }, + ); + } + + if (result.status !== 500 && errorText) { + try { + const errorJson = JSON.parse(errorText); + if (errorJson && errorJson.message) { + return NextResponse.json( + { message: errorJson.message }, + { status: result.status }, + ); + } + } catch (e) {} + } + return NextResponse.json( { message: "Invalid Credentials" }, { status: 401 },