diff --git a/app/share/[id]/page.tsx b/app/share/[id]/page.tsx index 46ed5d3..00a5a08 100644 --- a/app/share/[id]/page.tsx +++ b/app/share/[id]/page.tsx @@ -74,9 +74,9 @@ export default function PublicDashboardPage() { setData(dashboardData) setIsPasswordProtected(false) } catch (error: any) { - if (error.response?.status === 401 && error.response?.data?.is_protected) { + if ((error.status === 401 || error.response?.status === 401) && (error.data?.is_protected || error.response?.data?.is_protected)) { setIsPasswordProtected(true) - } else if (error.response?.status === 404) { + } else if (error.status === 404 || error.response?.status === 404) { toast.error('Site not found') } else if (!silent) { toast.error('Failed to load dashboard: ' + (error.message || 'Unknown error')) diff --git a/lib/api/client.ts b/lib/api/client.ts index 9b725d9..7d9ee0f 100644 --- a/lib/api/client.ts +++ b/lib/api/client.ts @@ -19,9 +19,12 @@ export function getSignupUrl(redirectPath = '/auth/callback') { export class ApiError extends Error { status: number - constructor(message: string, status: number) { + data?: any + + constructor(message: string, status: number, data?: any) { super(message) this.status = status + this.data = data } } @@ -136,7 +139,7 @@ async function apiRequest( error: 'Unknown error', message: `HTTP ${response.status}: ${response.statusText}`, })) - throw new ApiError(errorBody.message || errorBody.error || 'Request failed', response.status) + throw new ApiError(errorBody.message || errorBody.error || 'Request failed', response.status, errorBody) } return response.json()