Skip to content
This repository was archived by the owner on Jul 5, 2024. It is now read-only.

Commit 3e469d5

Browse files
authored
fix: more lax abort handling (#74)
1 parent d199eae commit 3e469d5

File tree

4 files changed

+5
-9
lines changed

4 files changed

+5
-9
lines changed

examples/async/src/tsonOptions.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {
2-
TsonAbortError,
32
TsonAsyncOptions,
43
createTsonParseEventSource,
54
createTsonParseJsonStreamResponse,
@@ -32,9 +31,6 @@ export const createJsonStreamResponse =
3231
export const parseJsonStreamResponse =
3332
createTsonParseJsonStreamResponse(tsonOptions);
3433

35-
export function isAbortError(err: unknown): err is TsonAbortError {
36-
return (
37-
err instanceof TsonAbortError ||
38-
(err instanceof Error && err.cause === TsonAbortError)
39-
);
34+
export function isAbortError(err: unknown): err is Error {
35+
return err instanceof Error && err.message.includes("aborted");
4036
}

src/async/asyncErrors.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export class TsonStreamInterruptedError extends TsonError {
4545

4646
export class TsonAbortError extends TsonError {
4747
constructor(cause: unknown) {
48-
super("Aborted", { cause });
48+
super("The user aborted a request.", { cause });
4949
this.name = "TsonAbortError";
5050
}
5151
}

src/async/deserializeAsync.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ function createTsonDeserializer(opts: TsonAsyncOptions) {
162162
}
163163

164164
return await init().catch((cause: unknown) => {
165-
throw new TsonError("Failed to initialize TSON stream", { cause });
165+
throw new TsonStreamInterruptedError(cause);
166166
});
167167
};
168168
}

src/index.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,6 @@ test("async: bad init", async () => {
134134
});
135135

136136
expect(err).toMatchInlineSnapshot(
137-
"[TsonError: Failed to initialize TSON stream]",
137+
"[TsonStreamInterruptedError: Stream interrupted: Stream ended unexpectedly (state 0)]",
138138
);
139139
});

0 commit comments

Comments
 (0)