fix: propagate API error data to handle protected dashboards correctly

This commit is contained in:
Usman Baig
2026-01-18 23:10:39 +01:00
parent 416939a61b
commit d03a688695
2 changed files with 7 additions and 4 deletions

View File

@@ -74,9 +74,9 @@ export default function PublicDashboardPage() {
setData(dashboardData) setData(dashboardData)
setIsPasswordProtected(false) setIsPasswordProtected(false)
} catch (error: any) { } 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) setIsPasswordProtected(true)
} else if (error.response?.status === 404) { } else if (error.status === 404 || error.response?.status === 404) {
toast.error('Site not found') toast.error('Site not found')
} else if (!silent) { } else if (!silent) {
toast.error('Failed to load dashboard: ' + (error.message || 'Unknown error')) toast.error('Failed to load dashboard: ' + (error.message || 'Unknown error'))

View File

@@ -19,9 +19,12 @@ export function getSignupUrl(redirectPath = '/auth/callback') {
export class ApiError extends Error { export class ApiError extends Error {
status: number status: number
constructor(message: string, status: number) { data?: any
constructor(message: string, status: number, data?: any) {
super(message) super(message)
this.status = status this.status = status
this.data = data
} }
} }
@@ -136,7 +139,7 @@ async function apiRequest<T>(
error: 'Unknown error', error: 'Unknown error',
message: `HTTP ${response.status}: ${response.statusText}`, 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() return response.json()