@@ -73,7 +73,34 @@ async function fetchJobsAttemptRest (params) {
7373 } )
7474
7575 const headers = Object . fromEntries ( res . headers . entries ( ) )
76- const text = await res . text ( )
76+ let text = ''
77+ try {
78+ text = await res . text ( )
79+ } catch ( err ) {
80+ const summary = {
81+ status : res . status ,
82+ headers : redactHeaders ( headers ) ,
83+ bodyUsed : res . bodyUsed ,
84+ // Commonly useful when debugging truncated/gzipped payloads.
85+ contentEncoding : headers [ 'content-encoding' ] ,
86+ contentLength : headers [ 'content-length' ] ,
87+ githubRequestId : headers [ 'x-github-request-id' ] ,
88+ }
89+ throw new TypeError (
90+ `Failed to read jobs REST response body (${ inspect ( summary , { depth : 5 } ) } ): ${ inspect ( err , { depth : 5 } ) } `
91+ )
92+ }
93+
94+ if ( ! res . ok ) {
95+ const summary = {
96+ status : res . status ,
97+ headers : redactHeaders ( headers ) ,
98+ bodyLength : text . length ,
99+ bodyPrefix : text . slice ( 0 , 200 ) ,
100+ }
101+ throw new TypeError ( `GitHub REST request failed (${ inspect ( summary , { depth : 5 } ) } )` )
102+ }
103+
77104 try {
78105 return JSON . parse ( text )
79106 } catch ( err ) {
@@ -152,14 +179,19 @@ async function checkWorkflowJobs (id, attempt, page = 1) {
152179 let jobs = response ?. data ?. jobs
153180
154181 // If Octokit returns an invalid shape (including `data: ''`), fall back to a raw REST fetch.
182+ // `@octokit/request` may return `data: ""` if it fails to read/parse the response body.
155183 if ( ! Array . isArray ( jobs ) ) {
184+ const headers = response ?. headers || { }
156185 console . warn (
157186 `Octokit jobs response invalid; attempting REST fallback: ${ inspect ( {
158187 id,
159188 attempt,
160189 page,
161190 status : response ?. status ,
162191 url : response ?. url ,
192+ githubRequestId : headers ?. [ 'x-github-request-id' ] ,
193+ contentEncoding : headers ?. [ 'content-encoding' ] ,
194+ contentLength : headers ?. [ 'content-length' ] ,
163195 headers : redactHeaders ( response ?. headers ) ,
164196 data : response ?. data
165197 } , { depth : 5 } ) } `
@@ -169,7 +201,6 @@ async function checkWorkflowJobs (id, attempt, page = 1) {
169201 jobs = rest ?. jobs
170202 }
171203
172- // Octokit v5 format: response.data.jobs is an array.
173204 if ( ! Array . isArray ( jobs ) ) {
174205 throw new TypeError ( `Unexpected jobs response shape (${ inspect ( response , { depth : Infinity } ) } )` )
175206 }
0 commit comments