WIP - more progress with permissions

This commit is contained in:
Francisco Gaona
2025-12-28 06:48:03 +01:00
parent 88f656c3f5
commit ac4a4b68cd
8 changed files with 333 additions and 91 deletions

View File

@@ -45,7 +45,9 @@ export const useApi = () => {
toast.error('Your session has expired. Please login again.')
router.push('/login')
}
throw new Error('Unauthorized')
const error = new Error('Unauthorized')
;(error as any).status = 401
throw error
}
if (response.status === 403) {
@@ -59,17 +61,24 @@ export const useApi = () => {
router.push('/login')
}
}
throw new Error('Forbidden')
// Don't log 403 errors - create error with status flag
const error = new Error('Forbidden')
;(error as any).status = 403
throw error
}
if (!response.ok) {
// Try to get error details from response
const text = await response.text()
console.error('API Error Response:', {
status: response.status,
statusText: response.statusText,
body: text
})
// Only log unexpected errors (not 401 or 403 which are handled above)
if (response.status !== 401 && response.status !== 403) {
console.error('API Error Response:', {
status: response.status,
statusText: response.statusText,
body: text
})
}
let errorMessage = `HTTP error! status: ${response.status}`
if (text) {