@@ -95,14 +95,45 @@ function createRequestError(
9595 return requestError ;
9696}
9797
98+ const PROXY_ERROR_PATTERNS = [
99+ 'socket disconnected before secure TLS connection' ,
100+ 'ECONNRESET' ,
101+ 'ECONNREFUSED' ,
102+ 'DEPTH_ZERO_SELF_SIGNED_CERT' ,
103+ 'UNABLE_TO_VERIFY_LEAF_SIGNATURE' ,
104+ 'CERT_HAS_EXPIRED' ,
105+ 'self signed certificate' ,
106+ 'proxy' ,
107+ 'ETIMEDOUT' ,
108+ 'EHOSTUNREACH' ,
109+ 'ENETUNREACH' ,
110+ ] ;
111+
112+ function isProxyRelatedError ( error : unknown ) : boolean {
113+ const msg =
114+ error instanceof Error
115+ ? error . message
116+ : typeof error === 'string'
117+ ? error
118+ : '' ;
119+ const lower = msg . toLowerCase ( ) ;
120+ return PROXY_ERROR_PATTERNS . some ( ( p ) => lower . includes ( p . toLowerCase ( ) ) ) ;
121+ }
122+
98123async function query ( url : string , options : RuntimeRequestInit ) {
99124 const baseUrl = await getBaseUrl ;
100125 const fullUrl = `${ baseUrl } ${ url } ` ;
101126 let resp : RuntimeResponse ;
102127 try {
103128 resp = await runtimeFetch ( fullUrl , options ) ;
104129 } catch ( error ) {
105- throw createRequestError ( error , fullUrl ) ;
130+ const baseError = createRequestError ( error , fullUrl ) ;
131+ if ( isProxyRelatedError ( error ) ) {
132+ throw new Error (
133+ `${ baseError . message } \n\n${ t ( 'proxyNetworkError' ) } \n${ t ( 'proxyNetworkErrorTips' ) } ` ,
134+ ) ;
135+ }
136+ throw baseError ;
106137 }
107138 const text = await resp . text ( ) ;
108139 let json : any ;
@@ -230,6 +261,13 @@ export async function uploadFile(fn: string, key?: string) {
230261 body : form ,
231262 } ) ;
232263 } catch ( error ) {
264+ if ( isProxyRelatedError ( error ) ) {
265+ const rawMessage =
266+ error instanceof Error ? error . message : String ( error ) ;
267+ throw new Error (
268+ `${ rawMessage } \n\n${ t ( 'proxyNetworkError' ) } \n${ t ( 'proxyNetworkErrorTips' ) } ` ,
269+ ) ;
270+ }
233271 throw createRequestError ( error , realUrl ) ;
234272 }
235273
0 commit comments