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
14 changes: 14 additions & 0 deletions apps/server/src/preview/ServerBrowserPage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,17 @@ describe("server browser drag", () => {
}
});
});

describe("server browser net errors", () => {
it.each([
["net::ERR_CONNECTION_REFUSED", "ERR_CONNECTION_REFUSED", -102],
[
"page.goto: net::ERR_HTTP2_PROTOCOL_ERROR at https://localhost:5173/",
"ERR_HTTP2_PROTOCOL_ERROR",
-2,
],
["net::ERR_TLS13_DOWNGRADE_DETECTED", "ERR_TLS13_DOWNGRADE_DETECTED", -2],
])("reads the whole error name from %j", (errorText, description, code) => {
expect(ServerBrowserPage.parseNetError(errorText)).toEqual({ description, code });
});
});
3 changes: 2 additions & 1 deletion apps/server/src/preview/ServerBrowserPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,8 @@ const NET_ERROR_CODES: Readonly<Record<string, number>> = {
};

export const parseNetError = (errorText: string) => {
const description = /ERR_[A-Z_]+/.exec(errorText)?.[0] ?? errorText;
// Names can hold digits, as in ERR_HTTP2_PROTOCOL_ERROR.
const description = /ERR_[A-Z\d_]+/.exec(errorText)?.[0] ?? errorText;
return { description, code: NET_ERROR_CODES[description] ?? -2 };
};

Expand Down
Loading