@@ -44,7 +44,7 @@ async function checkKeys(env) {
4444 if ( ! key || ! secret ) return { success : false , message : 'Keys are not set' } ;
4545
4646 try {
47- const client = new Spot ( key , secret , { baseURL : cfg . baseURL } ) ;
47+ const client = new Spot ( key , secret , { baseURL : cfg . baseURL , timeout : 5000 } ) ;
4848 const res = await client . account ( { omitZeroBalances : true } ) ;
4949 return {
5050 success : true ,
@@ -53,7 +53,20 @@ async function checkKeys(env) {
5353 } ;
5454 } catch ( err ) {
5555 const data = err . response ?. data ;
56- const message = [ data ?. code , data ?. msg || err . message ] . filter ( Boolean ) . join ( ' ' ) ;
56+ // A rejected key comes back from Binance as a parsed JSON body {code, msg}.
57+ // Anything else — no response at all (DNS failure, refused connection, our
58+ // own timeout), or a response that isn't that shape (503/502/HTML "under
59+ // maintenance" page) — means the request never reached the account check,
60+ // so it must not be reported as an invalid key.
61+ if ( ! data || typeof data !== 'object' || data . code === undefined ) {
62+ // The body is a gateway/maintenance page (HTML, plain text), not something
63+ // worth showing raw — the status code already says everything useful.
64+ const reason = err . response
65+ ? `HTTP ${ err . response . status } ${ err . response . statusText || '' } ` . trim ( )
66+ : err . code || err . message || 'unknown error' ;
67+ return { success : false , offline : true , message : `Exchange unreachable (${ reason } )` } ;
68+ }
69+ const message = [ data . code , data . msg || err . message ] . filter ( Boolean ) . join ( ' ' ) ;
5770 return { success : false , message : message || 'Request failed' } ;
5871 }
5972}
0 commit comments