chore: make all request errors inherit the same parent class

This commit is contained in:
Yohan Boniface 2024-01-30 19:10:37 +01:00
parent 6b5ecac9c6
commit 325880f86f
2 changed files with 7 additions and 4 deletions

View file

@ -1,9 +1,9 @@
import * as L from '../../vendors/leaflet/leaflet-src.esm.js'
import URLs from './urls.js'
import { Request, ServerRequest, HTTPError, NOKError } from './request.js'
import { Request, ServerRequest, RequestError, HTTPError, NOKError } from './request.js'
// Import modules and export them to the global scope.
// For the not yet module-compatible JS out there.
// Copy the leaflet module, it's expected by leaflet plugins to be writeable.
window.L = { ...L }
window.umap = { URLs, Request, ServerRequest, HTTPError, NOKError }
window.umap = { URLs, Request, ServerRequest, RequestError, HTTPError, NOKError }

View file

@ -1,14 +1,17 @@
// Uses `L._`` from Leaflet.i18n which we cannot import as a module yet
import { Evented, DomUtil } from '../../vendors/leaflet/leaflet-src.esm.js'
export class HTTPError extends Error {
export class RequestError extends Error {}
export class HTTPError extends RequestError {
constructor(message) {
super(message)
this.name = this.constructor.name
}
}
export class NOKError extends Error {
export class NOKError extends RequestError {
constructor(response) {
super(response.status)
this.response = response