File tree Expand file tree Collapse file tree
packages/client-runtime/src/errors Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { describe , expect , it } from "vite-plus/test" ;
22
3+ import { NETWORK_BLOCKING_HINT } from "./network.ts" ;
34import { isTransportConnectionErrorMessage , sanitizeThreadErrorMessage } from "./transport.ts" ;
45
56describe ( "isTransportConnectionErrorMessage" , ( ) => {
@@ -30,6 +31,20 @@ describe("isTransportConnectionErrorMessage", () => {
3031 expect ( isTransportConnectionErrorMessage ( "ClientProtocolError: socket closed" ) ) . toBe ( true ) ;
3132 } ) ;
3233
34+ it ( "recognizes relay connection errors that carry the network hint" , ( ) => {
35+ for ( const sentence of [
36+ "Relay environment disconnected." ,
37+ "Relay environment could not establish a WebSocket connection." ,
38+ ] ) {
39+ expect ( isTransportConnectionErrorMessage ( `${ sentence } ${ NETWORK_BLOCKING_HINT } ` ) ) . toBe ( true ) ;
40+ }
41+ expect (
42+ isTransportConnectionErrorMessage (
43+ "Your ChatGPT connection expired or was disconnected. Sign in again." ,
44+ ) ,
45+ ) . toBe ( false ) ;
46+ } ) ;
47+
3348 it ( "returns true for the T3 server WebSocket message" , ( ) => {
3449 expect ( isTransportConnectionErrorMessage ( "Unable to connect to the T3 server WebSocket." ) ) . toBe (
3550 true ,
Original file line number Diff line number Diff line change 1+ import { NETWORK_BLOCKING_HINT } from "./network.ts" ;
2+
3+ const escapeRegExp = ( text : string ) => text . replace ( / [ . * + ? ^ $ { } ( ) | [ \] \\ ] / g, "\\$&" ) ;
4+
15const TRANSPORT_ERROR_PATTERNS = [
26 / \b S o c k e t C l o s e E r r o r \b / i,
37 / \b S o c k e t O p e n E r r o r \b / i,
48 / \b S o c k e t i s n o t c o n n e c t e d \b / i,
59 / U n a b l e t o c o n n e c t t o t h e T 3 s e r v e r W e b S o c k e t \. / i,
6- / \b i s n o t c o n n e c t e d \. $ / i,
7- / \b d i s c o n n e c t e d \. $ / i,
8- / \b c o u l d n o t e s t a b l i s h a W e b S o c k e t c o n n e c t i o n \. $ / i,
10+ // The RPC session appends the network hint for relay connections. Any other
11+ // trailing text means a different error that the user should still see.
12+ new RegExp (
13+ `\\b(?:is not connected|disconnected|could not establish a WebSocket connection)\\.(?: ${ escapeRegExp ( NETWORK_BLOCKING_HINT ) } )?$` ,
14+ "i" ,
15+ ) ,
916 / \b C l i e n t P r o t o c o l E r r o r \b / i,
1017 / \b R p c C l i e n t E r r o r \b / i,
1118 / \b p i n g t i m e o u t \b / i,
You can’t perform that action at this time.
0 commit comments