Skip to content

Commit

Permalink
Merge pull request #410 from Inist-CNRS/fix-corhal-fetch-3
Browse files Browse the repository at this point in the history
fix: 🐛 token too long in http headers
  • Loading branch information
touv authored May 17, 2024
2 parents e380c6b + 6555054 commit e4ccd1a
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions packages/conditor/src/corhal-fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down

0 comments on commit e4ccd1a

Please sign in to comment.