Skip to content

Commit 55e5da1

Browse files
committed
Fixup combined error
1 parent 0bfc4f6 commit 55e5da1

2 files changed

Lines changed: 20 additions & 17 deletions

File tree

packages/api-client-core/spec/support.spec.ts

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,41 +51,38 @@ describe("support utilities", () => {
5151
).toThrowErrorMatchingInlineSnapshot(`"[Network] foobar"`);
5252
});
5353

54-
test("throws an actual error object and not a string so that the user gets a stack message", () => {
55-
try {
54+
test("throws the operation error if with the full network error as a string if there is no error message", () => {
55+
expect(() =>
5656
assertOperationSuccess(
5757
{
5858
operation: null as any,
5959
data: null,
60-
error: new CombinedError({ networkError: new Error("foobar") }),
60+
error: new CombinedError({ networkError: new Error() }),
6161
stale: false,
6262
hasNext: false,
6363
},
6464

6565
["foo", "bar"]
66-
);
67-
} catch (error: any) {
68-
expect(error).toBeInstanceOf(Error);
69-
}
66+
)
67+
).toThrow(`[Network] No message, error:`);
7068
});
7169

72-
test("throws the operation error if there's multiple network errors on the operation", () => {
73-
expect(() =>
70+
test("throws an actual error object and not a string so that the user gets a stack message", () => {
71+
try {
7472
assertOperationSuccess(
7573
{
7674
operation: null as any,
7775
data: null,
78-
error: new CombinedError({ networkError: [new Error("foo"), new Error("foo")] as any }),
76+
error: new CombinedError({ networkError: new Error("foobar") }),
7977
stale: false,
8078
hasNext: false,
8179
},
8280

8381
["foo", "bar"]
84-
)
85-
).toThrowErrorMatchingInlineSnapshot(`
86-
"[Network] foo
87-
[Network] foo"
88-
`);
82+
);
83+
} catch (error: any) {
84+
expect(error).toBeInstanceOf(Error);
85+
}
8986
});
9087

9188
test("throws the operation error if there's a error on the operation", () => {

packages/api-client-core/src/support.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,14 @@ export const getNonNullableError = (response: Result & { fetching: boolean }, da
316316

317317
export const assertOperationSuccess = (response: OperationResult<any>, dataPath: string[], throwOnEmptyData = false) => {
318318
if (response.error) {
319-
if (response.error instanceof CombinedError && (response.error.networkError as any as Error[])?.length) {
320-
response.error.message = (response.error.networkError as any as Error[]).map((error) => "[Network] " + error.message).join("\n");
319+
if (response.error instanceof CombinedError && response.error.networkError) {
320+
if (response.error.networkError?.message) {
321+
response.error.message = `[Network] ${response.error.networkError.message}`;
322+
} else {
323+
response.error.message = `[Network] No message, error: string(response.error.networkError) \nstack: ${String(
324+
response.error.networkError.stack
325+
)}}`;
326+
}
321327
}
322328
throw response.error;
323329
}

0 commit comments

Comments
 (0)