Skip to content

Commit af3d025

Browse files
committed
fix: improve error message relay from api
1 parent 9155956 commit af3d025

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

utils/next/orvalError.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { type DmError } from "@squonk/data-manager-client";
33

44
import { type AxiosError } from "axios";
55

6+
import { nullEmptyString } from "../text";
7+
68
const getMessageFromResponse = <TError>(error: AxiosError<TError>, field: keyof TError) => {
79
const apiErrorData = error.response?.data;
810
return apiErrorData?.[field];
@@ -49,6 +51,11 @@ export const getErrorMessage = (error: APIErrorResponse | AxiosError | null): st
4951
}
5052
}
5153

52-
// we haven't got a message from the error
53-
return "Error: no information provided";
54+
// try get an error message from the error objects, skipping "", then fallback to a generic message
55+
return (
56+
(typeof error?.response?.data === "string" ? nullEmptyString(error.response.data) : null) ??
57+
nullEmptyString(error?.response?.statusText) ??
58+
nullEmptyString(error?.message) ??
59+
"Error: no information provided"
60+
);
5461
};

0 commit comments

Comments
 (0)