From 4bef8ddb553d8c7ab9da5b8388308935f360045f Mon Sep 17 00:00:00 2001 From: Richard87 Date: Mon, 27 Jan 2025 11:31:56 +0100 Subject: [PATCH] Dont fail on parsing status code --- src/store/utils/index.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/store/utils/index.ts b/src/store/utils/index.ts index 5e35a79f0..417f89366 100644 --- a/src/store/utils/index.ts +++ b/src/store/utils/index.ts @@ -6,6 +6,15 @@ import type { FetchQueryError } from '../types'; type ManagedErrors = FetchQueryError | SerializedError | Error | unknown; +function getStatusPhrase(code: number | undefined) { + try { + return code ? getReasonPhrase(code) : 'unknown'; + } catch (e) { + console.warn("unknown status code", {e, code}) + return "unknown" + } +} + export function getFetchErrorData(error: ManagedErrors): { code?: number; message: string; @@ -49,7 +58,7 @@ export function getFetchErrorData(error: ManagedErrors): { return { code: code, error: isFetchBaseQueryError(error) ? "server error" : error.error, - message: "failed to fetch data: " + (code ? getReasonPhrase(code) : "unknown") + message: "failed to fetch data: " + getStatusPhrase(code) } }