import { backendErrorResponse, BackendError, backendRequest } from "@/lib/backend"; import type { ApiEnvelope, AuthUser, StoreDetail } from "@/lib/types"; function fallbackStore(user: AuthUser): StoreDetail | null { if (!user.storeId) return null; return { id: user.storeId, name: user.storeName ?? "当前门店", address: null, phone: null, status: undefined, employees: [] }; } export async function GET() { try { const user = await backendRequest("/auth/me"); if (!user.storeId) { return Response.json({ success: true, data: null } satisfies ApiEnvelope); } try { const store = await backendRequest(`/stores/${user.storeId}`); return Response.json({ success: true, data: store } satisfies ApiEnvelope); } catch (error) { if (error instanceof BackendError && [403, 404].includes(error.status)) { return Response.json({ success: true, data: fallbackStore(user) } satisfies ApiEnvelope); } throw error; } } catch (error) { return backendErrorResponse(error); } }