(path, body, opts = {})
| 523 | } |
| 524 | |
| 525 | async _proxyHttp(path, body, opts = {}) { |
| 526 | if (!this.hubUrl) throw Object.assign(new Error('Hub not configured'), { statusCode: 503 }); |
| 527 | |
| 528 | const method = (opts.method || 'POST').toUpperCase(); |
| 529 | const query = opts.query && typeof opts.query === 'object' ? opts.query : null; |
| 530 | const timeoutMs = opts.timeoutMs || 30_000; |
| 531 | |
| 532 | let fullPath = path; |
| 533 | if (query) { |
| 534 | const qs = new URLSearchParams(); |
| 535 | for (const [k, v] of Object.entries(query)) { |
| 536 | if (v !== undefined && v !== null) qs.set(k, String(v)); |
| 537 | } |
| 538 | const qsString = qs.toString(); |
| 539 | if (qsString) fullPath += (path.includes('?') ? '&' : '?') + qsString; |
| 540 | } |
| 541 | |
| 542 | const endpoint = `${this.hubUrl}${fullPath}`; |
| 543 | const init = { |
| 544 | method, |
| 545 | headers: this.lifecycle._buildHeaders(), |
| 546 | signal: AbortSignal.timeout(timeoutMs), |
| 547 | }; |
| 548 | if (method !== 'GET' && method !== 'HEAD') { |
| 549 | init.body = JSON.stringify(body || {}); |
| 550 | } |
| 551 | |
| 552 | const res = await hubFetch(endpoint, init); |
| 553 | |
| 554 | if (res.status === 403 || res.status === 401) { |
| 555 | const recovered = await this.lifecycle.reAuthenticate(); |
| 556 | if (recovered) { |
| 557 | const retryInit = { |
| 558 | method, |
| 559 | headers: this.lifecycle._buildHeaders(), |
| 560 | signal: AbortSignal.timeout(timeoutMs), |
| 561 | }; |
| 562 | if (method !== 'GET' && method !== 'HEAD') { |
| 563 | retryInit.body = JSON.stringify(body || {}); |
| 564 | } |
| 565 | const retry = await hubFetch(endpoint, retryInit); |
| 566 | if (!retry.ok) { |
| 567 | const text = await retry.text().catch(() => ''); |
| 568 | throw Object.assign(new Error(`Hub ${retry.status}: ${sanitizeHubResponseForLog(text)}`), { statusCode: retry.status }); |
| 569 | } |
| 570 | return retry.json(); |
| 571 | } |
| 572 | const text = await res.text().catch(() => ''); |
| 573 | throw Object.assign(new Error(`Hub ${res.status} (re-auth failed): ${sanitizeHubResponseForLog(text)}`), { statusCode: res.status }); |
| 574 | } |
| 575 | |
| 576 | if (!res.ok) { |
| 577 | const text = await res.text().catch(() => ''); |
| 578 | const err = Object.assign(new Error(`Hub ${res.status}: ${sanitizeHubResponseForLog(text)}`), { statusCode: res.status }); |
| 579 | if (res.status === 429) err.retryAfterMs = parseRetryAfterMs(res, text); |
| 580 | throw err; |
| 581 | } |
| 582 |
no test coverage detected