Skip to content

Commit 1e0b822

Browse files
0einstein0slint
authored andcommitted
utils: updated string error handling in flattenAndCategorizeErrors
1 parent 4466cea commit 1e0b822

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/lib/utils/flattenAndCategorizeErrors.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@
55
// under the terms of the MIT License; see LICENSE file for more details.
66

77
export function flattenAndCategorizeErrors(obj, prefix = "") {
8-
if (!obj || typeof obj !== "object") {
9-
throw Error("Invalid input: expected an object");
10-
}
11-
128
const flattenedErrors = {};
139
const severityChecks = {};
1410

15-
// Handle direct severity-based error objects
11+
// If obj is a string, treat it as a single error message i.e. old error format
12+
if (typeof obj === "string") {
13+
flattenedErrors[prefix || "error"] = obj;
14+
return { flattenedErrors, severityChecks };
15+
}
16+
17+
// Handle direct severity-based error objects i.e. new error format
1618
if (obj.message && obj.severity) {
1719
severityChecks[prefix || "error"] = obj;
1820
return { flattenedErrors, severityChecks };

0 commit comments

Comments
 (0)