From 65207ea853684bea74116d0b183be3e2e8951088 Mon Sep 17 00:00:00 2001 From: n0099 Date: Sat, 24 Feb 2024 21:38:14 +0800 Subject: [PATCH] * now will not show `error` when it's null * now will split the array of `errorInfo` into `

` tags @ `` * replace field `response` to its `.body.text()` @ `api/index.ts.FetchResponseError` * rename class name from camelCase to kebab-case @ `` & `` @ fe --- fe/src/api/index.ts | 9 ++++---- .../placeholders/PlaceholderError.vue | 22 +++++++++---------- fe/src/components/widgets/SelectUser.vue | 8 +++---- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/fe/src/api/index.ts b/fe/src/api/index.ts index 40a40396..636fc782 100644 --- a/fe/src/api/index.ts +++ b/fe/src/api/index.ts @@ -15,8 +15,8 @@ export class ApiResponseError extends Error { } } export class FetchResponseError extends Error { - public constructor(public readonly response: Response) { - super(JSON.stringify(response)); + public constructor(public readonly bodyText: string) { + super(bodyText); } } // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents @@ -40,10 +40,11 @@ export const queryFunction = (endpoint: string, queryPar { headers: { Accept: 'application/json' }, signal: queryContext.signal } ); const json = await response.json() as TResponse; - if (!response.ok) - throw new FetchResponseError(response); if (isApiError(json)) throw new ApiResponseError(json.errorCode, json.errorInfo); + const response2 = response.clone(); + if (!response.ok) + throw new FetchResponseError(await response2.text()); return json; } finally { diff --git a/fe/src/components/placeholders/PlaceholderError.vue b/fe/src/components/placeholders/PlaceholderError.vue index 6235cce0..ec051d6b 100644 --- a/fe/src/components/placeholders/PlaceholderError.vue +++ b/fe/src/components/placeholders/PlaceholderError.vue @@ -1,23 +1,23 @@