Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/connect-web-bench/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ usually do. We repeat this for an increasing number of RPCs.

| code generator | RPCs | bundle size | minified | compressed |
| -------------- | ---: | ----------: | --------: | ---------: |
| Connect-ES | 1 | 278,958 b | 177,578 b | 35,936 b |
| Connect-ES | 4 | 283,210 b | 180,680 b | 36,713 b |
| Connect-ES | 8 | 288,073 b | 185,111 b | 37,629 b |
| Connect-ES | 16 | 297,201 b | 192,738 b | 39,158 b |
| Connect-ES | 1 | 279,002 b | 177,602 b | 35,928 b |
| Connect-ES | 4 | 283,254 b | 180,704 b | 36,717 b |
| Connect-ES | 8 | 288,117 b | 185,135 b | 37,672 b |
| Connect-ES | 16 | 297,245 b | 192,762 b | 39,185 b |
| gRPC-Web | 1 | 876,563 b | 548,495 b | 52,300 b |
| gRPC-Web | 4 | 928,964 b | 580,477 b | 54,673 b |
| gRPC-Web | 8 | 1,004,833 b | 628,223 b | 57,118 b |
Expand Down
10 changes: 5 additions & 5 deletions packages/connect-web-bench/chart.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions packages/connect/src/connect-error.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,20 @@ describe("ConnectError", () => {
expect(got.rawMessage).toBe("Not permitted");
expect(got.cause).toBe(error);
});
it("wraps AbortError with code canceled", () => {
// abort() on AbortSignal aborts with a AbortError
const error: unknown = new DOMException("foo", "AbortError");
const got = ConnectError.from(error);
expect(got.code).toBe(Code.Canceled);
expect(got.rawMessage).toBe("foo");
});
it("wraps TimeoutError with code canceled", () => {
// AbortSignal.timeout() aborts with a TimeoutError
const error: unknown = new DOMException("foo", "TimeoutError");
const got = ConnectError.from(error);
expect(got.code).toBe(Code.Canceled);
expect(got.rawMessage).toBe("foo");
});
});
describe("instanceof", () => {
it("works for the actual ConnectError", () => {
Expand Down
11 changes: 5 additions & 6 deletions packages/connect/src/connect-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ export class ConnectError extends Error {
* Convert any value - typically a caught error into a ConnectError,
* following these rules:
* - If the value is already a ConnectError, return it as is.
* - If the value is an AbortError from the fetch API, return the message
* of the AbortError with code Canceled.
* - If the value is an AbortError or TimeoutError from the fetch API, return
* the message of the error with code Canceled.
* - For other Errors, return the error message with code Unknown by default.
* - For other values, return the values String representation as a message,
* with the code Unknown by default.
Expand All @@ -115,10 +115,9 @@ export class ConnectError extends Error {
return reason;
}
if (reason instanceof Error) {
if (reason.name == "AbortError") {
// Fetch requests can only be canceled with an AbortController.
// We detect that condition by looking at the name of the raised
// error object, and translate to the appropriate status code.
if (reason.name == "AbortError" || reason.name == "TimeoutError") {
// Fetch requests can only be canceled with an AbortController,
// or with AbortSignal.timeout().
return new ConnectError(reason.message, Code.Canceled);
}
return new ConnectError(
Expand Down