From 5f2aff5f04b4a4b00d507507677a2d7c7fa5a946 Mon Sep 17 00:00:00 2001 From: Nicolas Thouvenin Date: Fri, 17 May 2024 12:07:58 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20token=20too=20long=20in?= =?UTF-8?q?=20http=20headers?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/conditor/src/corhal-fetch.js | 11 ++++++----- packages/core/src/engine.js | 7 +++++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/conditor/src/corhal-fetch.js b/packages/conditor/src/corhal-fetch.js index 66fce2f8..e1e7842e 100644 --- a/packages/conditor/src/corhal-fetch.js +++ b/packages/conditor/src/corhal-fetch.js @@ -10,7 +10,9 @@ import each from 'async-each-series'; const request = (url, parameters) => async () => { const response = await fetch(url, parameters); if (!response.ok) { - throw new Error(response.statusText); + const err = new Error(response.statusText); + err.body = await response.json(); + throw err; } return response; }; @@ -69,7 +71,7 @@ export default async function CORHALFetch(data, feed) { headers: { 'Content-Type': 'application/json', }, - body: JSON.stringify(data), + body: JSON.stringify({ ...data, envelope: true }), }; const options = { retries, @@ -100,7 +102,7 @@ export default async function CORHALFetch(data, feed) { const { headers: headersBis, body: noticesBis } = await responseBis.json(); loop(stream, noticesBis, headersBis['after-key-token']); } catch (e) { - console.error(`Error with ${url}/after/`, e.message); + console.error(`Error with ${url}/after/`, e.message, e.body); stream.end(); } } else { @@ -110,8 +112,7 @@ export default async function CORHALFetch(data, feed) { try { const output = ezs.createStream(ezs.objectMode()); const response = await retry(request(cURL.href, parameters), options); - const headers = response.headers.raw(); - const notices = await response.json(); + const { headers, body: notices } = await response.json(); await loop(output, notices, headers['after-key-token']); await feed.flow(output); } catch (e) { diff --git a/packages/core/src/engine.js b/packages/core/src/engine.js index f8b12897..509441df 100644 --- a/packages/core/src/engine.js +++ b/packages/core/src/engine.js @@ -42,7 +42,7 @@ function decreaseCounter() { counter -= 1; } -function createErrorWith(error, index, funcName, funcParams, chunk) { +function createObjectError(error, index, funcName, funcParams, chunk) { const stk = String(error.stack).split('\n'); const prefix = `item #${index} `; const erm = stk.shift().replace(prefix, ''); @@ -62,6 +62,9 @@ function createErrorWith(error, index, funcName, funcParams, chunk) { chunk, }); Error.captureStackTrace(err, createErrorWith); +} +function createErrorWith(error, index, funcName, funcParams, chunk) { + const err = createObjectError(error, index, funcName, funcParams, chunk); debug('ezs')('Caught an', err); return err; } @@ -176,7 +179,7 @@ export default class Engine extends SafeTransform { const push = (data) => { if (data === null) { this.nullWasSent = true; - this.nullWasSentError = createErrorWith(new Error('As a reminder, the end was recorded at this point'), currentIndex, this.funcName, this.params, chunk); + this.nullWasSentError = createObjectError(new Error('As a reminder, the end was recorded at this point'), currentIndex, this.funcName, this.params, chunk); } else if (this.nullWasSent && !this.errorWasSent) { console.warn(createErrorWith(new Error('Oops, that\'s going to crash ?'), currentIndex, this.funcName, this.params, chunk)); return warn(this.nullWasSentError);