Skip to content

Commit

Permalink
handle 403 on lookup file
Browse files Browse the repository at this point in the history
  • Loading branch information
Minor Gordon committed Jan 31, 2024
1 parent 6b371bd commit 006e6d0
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
12 changes: 12 additions & 0 deletions __tests__/SchemaDotOrgDataSet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,16 @@ describe("SchemaDotOrgDataSet", () => {
await administrativeAreaClassSubset.samplePagesByIri();
expect(Object.keys(samplePagesByIri)).toHaveLength(1);
});

it("handles 4xx on a class lookup file", async () => {
if (process.env.CI) {
return;
}

const paintingClassSubset = classSubsets.find(
(classSubset) => classSubset.className === "Painting"
);
expect(paintingClassSubset).not.toBeUndefined();
expect(await paintingClassSubset?.payLevelDomainSubsets()).toHaveLength(0);
});
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,5 @@
},
"type": "module",
"types": "dist/index.d.ts",
"version": "3.0.4"
"version": "3.0.5"
}
34 changes: 20 additions & 14 deletions src/SchemaDotOrgDataSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,6 @@ namespace SchemaDotOrgDataSet {
this.showProgress = showProgress;
}

private async lookupCsvString(): Promise<string> {
return (
await streamToBuffer(await this.httpClient.get(this.lookupFileUrl))
).toString("utf8");
}

async *dataset() {
for (let fileI = 0; fileI < this.numberOfFiles; fileI++) {
for await (const quad of parseNQuadsStream(
Expand Down Expand Up @@ -308,14 +302,26 @@ namespace SchemaDotOrgDataSet {
return {};
}

const pldDataFileNames = Papa.parse(await this.lookupCsvString(), {
header: true,
}).data.reduce((map: Record<string, string>, row: any) => {
if (row["pld"].length > 0) {
map[row["pld"]] = row["file_lookup"];
}
return map;
}, {});
let pldDataFileNames: Record<string, string>;
try {
pldDataFileNames = Papa.parse(
(
await streamToBuffer(await this.httpClient.get(this.lookupFileUrl))
).toString("utf8"),
{
header: true,
}
).data.reduce((map: Record<string, string>, row: any) => {
if (row["pld"].length > 0) {
map[row["pld"]] = row["file_lookup"];
}
return map;
}, {});
} catch (e) {
// The 2022-12 Painting lookup returns 403
logger.error("error getting and parsing %s: %s", this.lookupFileUrl, e);
return {};
}

return (
Papa.parse(
Expand Down

0 comments on commit 006e6d0

Please sign in to comment.