From 09b4e2b33671a4ac471a22d8a733cdf0564ce3bf Mon Sep 17 00:00:00 2001 From: Ivan Vasilov Date: Tue, 4 Jun 2024 13:22:46 +0200 Subject: [PATCH] fix: Check the message if it's a string when handling API errors (#26436) Check for string when handling API errors. --- apps/studio/data/fetchers.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/apps/studio/data/fetchers.ts b/apps/studio/data/fetchers.ts index e9197229044..8176e9678b8 100644 --- a/apps/studio/data/fetchers.ts +++ b/apps/studio/data/fetchers.ts @@ -151,12 +151,14 @@ export const options: typeof _options = async (url, init) => { } export const handleError = (error: any): never => { - if (error && error.msg) { - throw new Error(error.msg) + if (error && typeof error.msg === 'string') { + throw new Error(error.msg || 'API error happened while trying to communicate with the server.') } - if (error && error.message) { - throw new Error(error.message) + if (error && typeof error.message === 'string') { + throw new Error( + error.message || 'API error happened while trying to communicate with the server.' + ) } console.error(error.stack)