Skip to content

Commit a55c978

Browse files
committed
Always add an error handler
Otherwise Maplibre logs every error, including AbortError, which is unhelpful. Our new default error handler calls the event handler if present, and if not, it also logs errors, except for AbortError.
1 parent 385b3cc commit a55c978

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/lib/MapLibre.svelte

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import FullscreenControl from './FullscreenControl.svelte';
1818
import ScaleControl from './ScaleControl.svelte';
1919
import type { Snippet } from 'svelte';
20+
import { handlers } from 'svelte/legacy';
2021
2122
interface Props {
2223
map?: maplibregl.Map;
@@ -223,6 +224,17 @@
223224
let sourcesToReAddAfterStyleChange: Record<string, SourceSpecification> | undefined =
224225
$state(undefined);
225226
227+
function handleError(event: ErrorEvent) {
228+
if (onerror) {
229+
onerror(event);
230+
} else if (event.error.name !== 'AbortError') {
231+
// If there's no error handler, just log it to match the default behavior from MapLibre.
232+
// But skip AbortError since that's a normal thing that happens inside certain sources,
233+
// and not useful to log.
234+
console.error(event);
235+
}
236+
}
237+
226238
function createMap(element: HTMLDivElement) {
227239
onHashChange();
228240
@@ -265,9 +277,7 @@
265277
loaded = true;
266278
});
267279
268-
if (onerror) {
269-
map.on('error', onerror);
270-
}
280+
map.on('error', handleError);
271281
272282
if (onmovestart) {
273283
map.on('movestart', onmovestart);

0 commit comments

Comments
 (0)