Skip to content

Commit dcca416

Browse files
committed
add more info about errors in Query.js
1 parent 9a81c8e commit dcca416

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

src/GraphQL/Client/Query.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1-
export function cause(err) {
2-
return String(err.cause || "");
3-
}
1+
const formatError = (err) => {
2+
if (!err) return "";
3+
const props = ["message", "code", "syscall", "hostname", "address", "port"]
4+
.filter((k) => err[k])
5+
.map((k) => `${k}: ${err[k]}`);
6+
if (err.cause) props.push(`cause: ${formatError(err.cause)}`);
7+
return props.join(", ");
8+
};
9+
10+
export const cause = (err) => {
11+
const c = err.cause;
12+
if (!c) return "";
13+
if (c instanceof AggregateError) {
14+
return [c.message, ...Array.from(c.errors, (e, i) => `[${i}] ${formatError(e)}`)].join("\n");
15+
}
16+
return formatError(c);
17+
};

0 commit comments

Comments
 (0)