Skip to content

Commit

Permalink
chore(get): improve error reporting on HTTP errors
Browse files Browse the repository at this point in the history
  • Loading branch information
reinierl committed Feb 4, 2023
1 parent 5c06eed commit 5c60ad5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
18 changes: 12 additions & 6 deletions src/commands/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,16 @@ export const get = async (moduleName: string, privacyPass?: string) => {
},
});

pipeline(
ocpiObjectStream,
privacyFilteringStream,
jsonEncodingStream,
stdout
);
try {
await pipeline(
ocpiObjectStream.on("error", () => console.debug("aargh!")),
privacyFilteringStream,
jsonEncodingStream,
stdout
);
} catch (err) {
console.log(
`Error fetching data from OCPI platform: ${(err as Error)?.message}`
);
}
};
24 changes: 15 additions & 9 deletions src/ocpi-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,16 +262,22 @@ export function fetchDataForModule<N extends ModuleID>(
return;
}

const firstPageParameters = { offset: 0, limit: size };
const nextPageData = await pullPageOfData(
session,
module,
nextPage === "notstarted" ? firstPageParameters : nextPage
);
if (nextPageData === "no such endpoint") {
throw new Error(`no endpoint found for module ${module.name}`);
let nextPageData;
try {
const firstPageParameters = { offset: 0, limit: size };
nextPageData = await pullPageOfData(
session,
module,
nextPage === "notstarted" ? firstPageParameters : nextPage
);
if (nextPageData === "no such endpoint") {
throw new Error(`no endpoint found for module ${module.name}`);
}
console.debug("Page fetched", nextPageData);
} catch (err) {
this.emit("error", err);
return;
}
console.debug("Page fetched", nextPageData);

nextPage = nextPageData.nextPage ?? "done";

Expand Down

0 comments on commit 5c60ad5

Please sign in to comment.