@@ -100,6 +100,32 @@ class GitHub extends Base {
100100 if ( remaining !== null ) this . rateLimit . remaining = parseInt ( remaining , 10 ) ;
101101 if ( reset !== null ) this . rateLimit . reset = parseInt ( reset , 10 ) ;
102102 if ( limit !== null ) this . rateLimit . limit = parseInt ( limit , 10 ) ;
103+
104+ // Debug: Warn if headers are missing but we are at default (implying no update ever happened)
105+ if ( remaining === null && this . rateLimit . remaining === 5000 ) {
106+ // Only log once or sparsely to avoid spam
107+ if ( ! this . _headerWarned ) {
108+ console . warn ( '[GitHub] Warning: `x-rate-limit-*` headers not found. Falling back to body (if available).' ) ;
109+ this . _headerWarned = true ;
110+ }
111+ }
112+ }
113+
114+ /**
115+ * Updates rate limit from GraphQL body.
116+ * @param {Object } rateLimit
117+ * @private
118+ */
119+ #updateFromBody( rateLimit ) {
120+ if ( ! rateLimit ) return ;
121+
122+ if ( rateLimit . remaining !== undefined ) this . rateLimit . remaining = rateLimit . remaining ;
123+ if ( rateLimit . limit !== undefined ) this . rateLimit . limit = rateLimit . limit ;
124+
125+ if ( rateLimit . resetAt ) {
126+ // GraphQL returns ISO string, we store epoch seconds
127+ this . rateLimit . reset = Math . floor ( new Date ( rateLimit . resetAt ) . getTime ( ) / 1000 ) ;
128+ }
103129 }
104130
105131 /**
@@ -140,6 +166,11 @@ class GitHub extends Base {
140166
141167 const json = await response . json ( ) ;
142168
169+ // Hook for body-based rate limit (more reliable for GraphQL)
170+ if ( json . data ?. rateLimit ) {
171+ this . #updateFromBody( json . data . rateLimit ) ;
172+ }
173+
143174 if ( json . errors ) {
144175 // Sometimes 502s come as 200 OK with errors body
145176 const isGatewayError = json . errors . some ( e => e . message ?. includes ( '502' ) || e . message ?. includes ( '504' ) ) ;
@@ -197,6 +228,9 @@ class GitHub extends Base {
197228 this . #updateRateLimit( response . headers ) ;
198229
199230 if ( ! response . ok ) {
231+ if ( response . status === 403 ) {
232+ this . rateLimit . remaining = 0 ;
233+ }
200234 throw new Error ( `REST Error: ${ response . status } ${ response . statusText } ` ) ;
201235 }
202236
0 commit comments