From 37f315cc57734a2c939685763c1e02eeb57e409e Mon Sep 17 00:00:00 2001 From: Brandon Liu Date: Fri, 14 Oct 2022 14:45:22 +0800 Subject: [PATCH] js: cleaner 404 error, change max directory depth to <= 3 --- js/index.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/js/index.ts b/js/index.ts index 6392da5..ec480fa 100644 --- a/js/index.ts +++ b/js/index.ts @@ -281,6 +281,11 @@ export class FetchSource implements Source { signal: signal, headers: { Range: "bytes=" + offset + "-" + (offset + length - 1) }, }); + + if (resp.status >= 300) { + throw Error("404"); + controller.abort(); + } const contentLength = resp.headers.get("Content-Length"); if (!contentLength || +contentLength !== length) { console.error( @@ -789,7 +794,7 @@ export class PMTiles { let d_o = header.rootDirectoryOffset; let d_l = header.rootDirectoryLength; - for (let depth = 0; depth < 5; depth++) { + for (let depth = 0; depth <= 3; depth++) { const directory = await this.cache.getDirectory( this.source, d_o,