fix: Check the message if it's a string when handling API errors (#26436)

Check for string when handling API errors.
This commit is contained in:
Ivan Vasilov authored and GitHub committed 2024-06-04 13:22:46 +02:00
1 parent 8886f011c0
commit 09b4e2b336
1 file changed
+6 -4
+6 -4
View File
@@ -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)