From 5f7ca86e4f887c4915ad8dc6d76c85a5ba9c5937 Mon Sep 17 00:00:00 2001 From: Gauthier Roebroeck Date: Fri, 30 May 2025 10:54:28 +0800 Subject: [PATCH] add response body in error cause for komgaclient --- next-ui/src/api/komga-client.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/next-ui/src/api/komga-client.ts b/next-ui/src/api/komga-client.ts index 1e9711b7..0f9d76b6 100644 --- a/next-ui/src/api/komga-client.ts +++ b/next-ui/src/api/komga-client.ts @@ -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 },