WIP - more progress with permissions
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user