From 2bd776820f4c972d059d96491192a86dbfbd4440 Mon Sep 17 00:00:00 2001 From: Brandon Liu Date: Sat, 17 Jun 2023 09:34:06 +0800 Subject: [PATCH] surface exceptions to MapLibre protocol API [fixes #196] --- js/adapters.ts | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/js/adapters.ts b/js/adapters.ts index de442d4..c49b678 100644 --- a/js/adapters.ts +++ b/js/adapters.ts @@ -123,14 +123,20 @@ export class Protocol { // TODO: create vector_layers if present to return valid TileJSON - instance.getHeader().then((h) => { - const tilejson = { - tiles: [params.url + "/{z}/{x}/{y}"], - minzoom: h.minZoom, - maxzoom: h.maxZoom, - }; - callback(null, tilejson, null, null); - }); + instance + .getHeader() + .then((h) => { + const tilejson = { + tiles: [params.url + "/{z}/{x}/{y}"], + minzoom: h.minZoom, + maxzoom: h.maxZoom, + }; + callback(null, tilejson, null, null); + }) + .catch((e) => { + callback(e, null, null, null); + }); + return { cancel: () => {}, }; @@ -181,7 +187,7 @@ export class Protocol { }) .catch((e) => { if ((e as Error).name !== "AbortError") { - throw e; + callback(e, null, null, null); } }); });