fix: [bending] API 연결 실패 시 안내 메시지 표시
- API 401/403/연결실패 시 구체적인 안내 메시지 표시 - 데이터 없음과 API 오류를 구분하여 사용자에게 안내
This commit is contained in:
@@ -49,8 +49,27 @@ public function index(Request $request, string $category = 'GUIDERAIL_MODEL'): V
|
||||
$params['size'] = $params['size'] ?? 30;
|
||||
$params['item_category'] = $category;
|
||||
|
||||
$response = $this->api()->get('/api/v1/guiderail-models', $params);
|
||||
$body = $response->successful() ? $response->json('data', []) : [];
|
||||
$apiError = null;
|
||||
try {
|
||||
$response = $this->api()->get('/api/v1/guiderail-models', $params);
|
||||
} catch (\Illuminate\Http\Client\ConnectionException $e) {
|
||||
$apiError = 'API 서버에 연결할 수 없습니다. API 서비스 상태를 확인해 주세요.';
|
||||
$response = null;
|
||||
}
|
||||
|
||||
if ($response && $response->successful()) {
|
||||
$body = $response->json('data', []);
|
||||
} else {
|
||||
$body = [];
|
||||
if (! $apiError && $response) {
|
||||
$apiError = match ($response->status()) {
|
||||
401 => 'API 인증이 필요합니다. SAM 서비스에 로그인하여 API를 연결해 주세요.',
|
||||
403 => 'API 접근 권한이 없습니다. 관리자에게 문의해 주세요.',
|
||||
default => "API 오류가 발생했습니다. (HTTP {$response->status()})",
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
$data = [
|
||||
'data' => $body['data'] ?? [],
|
||||
'total' => $body['total'] ?? 0,
|
||||
@@ -58,16 +77,17 @@ public function index(Request $request, string $category = 'GUIDERAIL_MODEL'): V
|
||||
'last_page' => $body['last_page'] ?? 1,
|
||||
];
|
||||
|
||||
$filterResponse = $this->api()->get('/api/v1/guiderail-models/filters');
|
||||
$filterOptions = $filterResponse->successful() ? $filterResponse->json('data', []) : [];
|
||||
$filterOptions = [];
|
||||
if (! $apiError) {
|
||||
$filterResponse = $this->api()->get('/api/v1/guiderail-models/filters');
|
||||
$filterOptions = $filterResponse->successful() ? $filterResponse->json('data', []) : [];
|
||||
}
|
||||
|
||||
if ($request->header('HX-Request')) {
|
||||
// 필터/검색 HTMX (hx-target="#items-table") → 파셜 반환
|
||||
if ($request->header('HX-Target') === 'items-table') {
|
||||
return view('bending.products.partials.table', ['items' => $data, 'config' => $config, 'category' => $category]);
|
||||
return view('bending.products.partials.table', ['items' => $data, 'config' => $config, 'category' => $category, 'apiError' => $apiError]);
|
||||
}
|
||||
|
||||
// 사이드바 등 그 외 HTMX → 전체 페이지 리로드
|
||||
return response('', 200)->header('HX-Redirect', route("bending.{$config['prefix']}.index", $request->query()));
|
||||
}
|
||||
|
||||
@@ -76,6 +96,7 @@ public function index(Request $request, string $category = 'GUIDERAIL_MODEL'): V
|
||||
'filterOptions' => $filterOptions,
|
||||
'config' => $config,
|
||||
'category' => $category,
|
||||
'apiError' => $apiError,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user