add response body in error cause for komgaclient

This commit is contained in:
Gauthier Roebroeck 2025-05-30 10:54:28 +08:00
parent 9a811b0b66
commit 72e81d83a8

View file

@ -4,9 +4,11 @@ import type {paths} from '@/generated/openapi/komga'
// Middleware that throws on error, so it works with Pinia Colada
const coladaMiddleware: Middleware = {
onResponse({response}: {response: Response}) {
if (!response.ok)
throw new Error(`${response.url}: ${response.status} ${response.statusText}`)
async onResponse({response}: { response: Response }) {
if (!response.ok) {
const body = await response.json()
throw new Error(`${response.url}: ${response.status} ${response.statusText}`, {cause: body})
}
// return response untouched
return undefined
},