src/cdp/errors.ts (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
export type CdpErrorKind =
| "transport_closed"
| "timeout"
| "session_not_found"
| "remote_error"
| "discovery_failed"
| "invalid_response";
export type CdpError = {
readonly kind: CdpErrorKind;
readonly message: string;
readonly method?: string;
};
// Chrome reports a dead session as a generic protocol error, so the message text is the only signal that a reattach — not a retry — is what will fix it.
export const classifyRemoteError = (message: string): CdpErrorKind =>
message.includes("Session with given id not found") ? "session_not_found" : "remote_error";
export const cdpError = (
kind: CdpErrorKind,
message: string,
method?: string,
): CdpError => ({ kind, message, ...(method !== undefined ? { method } : {}) });
|