File tree 1 file changed +7
-5
lines changed
1 file changed +7
-5
lines changed Original file line number Diff line number Diff line change 5
5
// under the terms of the MIT License; see LICENSE file for more details.
6
6
7
7
export function flattenAndCategorizeErrors ( obj , prefix = "" ) {
8
- if ( ! obj || typeof obj !== "object" ) {
9
- throw Error ( "Invalid input: expected an object" ) ;
10
- }
11
-
12
8
const flattenedErrors = { } ;
13
9
const severityChecks = { } ;
14
10
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
16
18
if ( obj . message && obj . severity ) {
17
19
severityChecks [ prefix || "error" ] = obj ;
18
20
return { flattenedErrors, severityChecks } ;
You can’t perform that action at this time.
0 commit comments