Skip to content

Commit

Permalink
fix headers
Browse files Browse the repository at this point in the history
  • Loading branch information
folland87 committed Dec 6, 2024
1 parent 8d9eb39 commit 27b7c09
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions src/jobs/sirene/fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ export const fetchSireneUpdates = async (startDate, endDate) => {
const result = await response.json();
await new Promise((resolve) => setTimeout(resolve, 2100));

if (!result || result.header.statut !== 200) {
if (!result || response.status !== 200) {
return [];
}

return result.header.curseurSuivant !== cursor
return response.headers.curseurSuivant !== cursor
? [
...result.etablissements,
...(await fetchPage(result.header.curseurSuivant)),
...(await fetchPage(response.headers.curseurSuivant)),
]
: result.etablissements;
};
Expand All @@ -50,11 +50,9 @@ export const fetchSirenDataById = async (sirenId) => {
const structure = {
siren: sirenId,
siret: null,
statut: result.header.statut,
message: result.header.message,
};

if (result.header.statut !== 200 || !result.unitesLegales?.[0]) {
if (response.status !== 200 || !result.unitesLegales?.[0]) {
return structure;
}

Expand Down Expand Up @@ -129,7 +127,7 @@ export const fetchSirenDataById = async (sirenId) => {
return structure;
} catch (error) {
console.error("Error fetching SIREN data:", error);
return { siren: sirenId, statut: 500 };
return { siren: sirenId, message: error.message };
}
};

Expand All @@ -151,10 +149,7 @@ export const fetchSiretDataById = async (siretId) => {
const result = await response.json();
await new Promise((resolve) => setTimeout(resolve, 2020));

structure.statut = result.header.statut;
structure.message = result.header.message;

if (result.header.statut !== 200 || !result.etablissements?.[0]) {
if (response.status !== 200 || !result.etablissements?.[0]) {
return structure;
}

Expand Down Expand Up @@ -225,7 +220,6 @@ export const fetchSiretDataById = async (siretId) => {
console.error("Error fetching SIRET data:", error);
return {
...structure,
statut: 500,
message: error.message,
};
}
Expand Down

0 comments on commit 27b7c09

Please sign in to comment.