chore: rename NokError and fix init param

This commit is contained in:
Yohan Boniface 2024-01-30 17:23:45 +01:00
parent da7d09527b
commit 3f1070c90d
2 changed files with 7 additions and 7 deletions

View file

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

View file

@ -8,7 +8,7 @@ export class HTTPError extends Error {
} }
} }
export class NokError extends Error { export class NOKError extends Error {
constructor(response) { constructor(response) {
super(response.status) super(response.status)
this.response = response this.response = response
@ -37,7 +37,7 @@ const BaseRequest = Evented.extend({
} }
if (!response.ok) { if (!response.ok) {
this.fire('dataload', { id: id }) this.fire('dataload', { id: id })
throw new NokError(response.status) throw new NOKError(response)
} }
// TODO // TODO
// - error handling // - error handling
@ -68,7 +68,7 @@ export const Request = BaseRequest.extend({
) )
return response return response
} catch (error) { } catch (error) {
if (error instanceof NokError) return this._onNok(error) if (error instanceof NOKError) return this._onNOK(error)
return this._onError(error) return this._onError(error)
} }
}, },
@ -85,7 +85,7 @@ export const Request = BaseRequest.extend({
this.ui.alert({ content: L._('Problem in the response'), level: 'error' }) this.ui.alert({ content: L._('Problem in the response'), level: 'error' })
}, },
_onNok: function (error) { _onNOK: function (error) {
this._onError(error) this._onError(error)
return error.response return error.response
}, },
@ -145,7 +145,7 @@ export const ServerRequest = Request.extend({
return [{}, null, error] return [{}, null, error]
}, },
_onNok: function (error) { _onNOK: function (error) {
if (error.status === 403) { if (error.status === 403) {
this.ui.alert({ this.ui.alert({
content: message || L._('Action not allowed :('), content: message || L._('Action not allowed :('),