Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Propagated HTTP errors in HTTPStore containsItem function #151

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/storage/httpStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ export class HTTPStore<UrlRoot extends string | URL=string> implements AsyncStor
// Just check headers if HEAD method supported
const method = this.supportedMethods.has(HTTPMethod.HEAD) ? HTTPMethod.HEAD : HTTPMethod.GET;
const value = await fetch(url, { ...this.fetchOptions, method });
if (value.status !== 200 && value.status !== 404) {
throw new HTTPError(String(value.status));
}
return value.status === 200;
}
}
3 changes: 3 additions & 0 deletions test/globalSetup.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ const express = require("express");

const app = express();
app.use(express.static("fixtures", { dotfiles: 'allow' }));
app.use('/forbidden', function (_req, res) {
return res.status(403).end();
});
const server = app.listen(3000);

module.exports = async () => {
Expand Down
8 changes: 7 additions & 1 deletion test/storage/httpStore.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
(global as any).fetch = require('node-fetch');

import { HTTPError } from "../../src/errors";
import { HTTPStore } from "../../src/storage/httpStore";
import { openArray } from "../../src/creation";

describe("Test MemoryStore", () => {
describe("Test HTTPStore", () => {

const simpleFixtureStoreLE = new HTTPStore("http://localhost:3000/simple_LE.zarr");
it("Can open simple fixture", async () => {
Expand Down Expand Up @@ -60,4 +61,9 @@ describe("Test MemoryStore", () => {
const z = await openArray({ store: baseUrlStore, path: "simple_LE.zarr" });
expect(z.shape).toEqual([8, 8]);
});

const forbiddenStore = new HTTPStore("http://localhost:3000/forbidden");
it("Propagates HTTP server error", async () => {
await expect(openArray({ store: forbiddenStore })).rejects.toThrowError(HTTPError);
});
});