hardening
This commit is contained in:
@@ -2,7 +2,15 @@
|
||||
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useRouter } from 'next/navigation'
|
||||
import { authFetch, clearToken, getApiBase, getToken } from '../../lib/auth'
|
||||
import {
|
||||
authFetch,
|
||||
authFetchOrThrow,
|
||||
clearToken,
|
||||
getApiBase,
|
||||
getToken,
|
||||
readResponseText,
|
||||
UnauthorizedError,
|
||||
} from '../../lib/auth'
|
||||
|
||||
type TimelineHop = {
|
||||
service: string
|
||||
@@ -502,16 +510,11 @@ export default function RequestTimelinePage({ params }: { params: { id: string }
|
||||
setModalMessage(null)
|
||||
}
|
||||
try {
|
||||
const response = await authFetch(`${baseUrl}/requests/${snapshot.request_id}/${path}`, {
|
||||
const response = await authFetchOrThrow(`${baseUrl}/requests/${snapshot.request_id}/${path}`, {
|
||||
method: 'POST',
|
||||
})
|
||||
if (!response.ok) {
|
||||
if (response.status === 401) {
|
||||
clearToken()
|
||||
router.push('/login')
|
||||
return
|
||||
}
|
||||
const text = await response.text()
|
||||
const text = await readResponseText(response)
|
||||
throw new Error(text || `Request failed: ${response.status}`)
|
||||
}
|
||||
const data = await response.json()
|
||||
@@ -538,6 +541,10 @@ export default function RequestTimelinePage({ params }: { params: { id: string }
|
||||
setModalMessage(message)
|
||||
}
|
||||
} catch (error) {
|
||||
if (error instanceof UnauthorizedError) {
|
||||
router.push('/login')
|
||||
return
|
||||
}
|
||||
console.error(error)
|
||||
const message = `${action.label} failed. Check the backend logs.`
|
||||
setActionMessage(message)
|
||||
@@ -582,7 +589,7 @@ export default function RequestTimelinePage({ params }: { params: { id: string }
|
||||
if (!ok) return
|
||||
const baseUrl = getApiBase()
|
||||
try {
|
||||
const response = await authFetch(
|
||||
const response = await authFetchOrThrow(
|
||||
`${baseUrl}/requests/${snapshot.request_id}/actions/grab`,
|
||||
{
|
||||
method: 'POST',
|
||||
@@ -595,17 +602,16 @@ export default function RequestTimelinePage({ params }: { params: { id: string }
|
||||
}
|
||||
)
|
||||
if (!response.ok) {
|
||||
if (response.status === 401) {
|
||||
clearToken()
|
||||
router.push('/login')
|
||||
return
|
||||
}
|
||||
const text = await response.text()
|
||||
const text = await readResponseText(response)
|
||||
throw new Error(text || `Request failed: ${response.status}`)
|
||||
}
|
||||
setActionMessage('Download sent to Sonarr/Radarr.')
|
||||
setModalMessage('Download sent to Sonarr/Radarr.')
|
||||
} catch (error) {
|
||||
if (error instanceof UnauthorizedError) {
|
||||
router.push('/login')
|
||||
return
|
||||
}
|
||||
console.error(error)
|
||||
const message = 'Download failed. Check the logs.'
|
||||
setActionMessage(message)
|
||||
|
||||
Reference in New Issue
Block a user