Source: bemap-model/bemap-error.js

/**
 * BeNomad BeMap JavaScript API - Error
 */

/**
 * @classdesc
 * Error class for the BeMap JS API.
 *
 * Constructor signature is fully backward-compatible with v1.0 (the
 * existing `code` / `message` fields are preserved and behave identically).
 * Version 1.5.0 adds three optional fields (`status`, `url`, `context`)
 * for richer error reporting from the modernised services, plus a set of
 * named code constants on the class for convenience.
 *
 * @public
 * @constructor
 * @param {Object} options
 * @param {String} [options.code] Error code (e.g. 'UNAUTHORIZED', 'NETWORK', 'ROUTING_NO_ROUTE').
 * @param {String} [options.message] Human-readable error message.
 * @param {Number} [options.status] HTTP status when the error came from an HTTP response.
 * @param {String} [options.url] Request URL when applicable.
 * @param {Object} [options.context] Additional debug payload (parsed response, engine-specific info).
 */
bemap.Error = function(options) {
    var opts = options || {};

    /**
     * @type {String}
     * @protected
     */
    this.code = opts.code ? opts.code : null;

    /**
     * @type {String}
     * @protected
     */
    this.message = opts.message ? opts.message : null;

    /**
     * HTTP status code if the error came from an HTTP response, otherwise null.
     * @type {Number}
     * @protected
     * @since 1.5.0
     */
    this.status = (opts.status !== undefined && opts.status !== null) ? opts.status : null;

    /**
     * Request URL associated with the error, when applicable.
     * @type {String}
     * @protected
     * @since 1.5.0
     */
    this.url = opts.url ? opts.url : null;

    /**
     * Free-form debug context (parsed response body, engine-specific debug info, etc.).
     * @type {Object}
     * @protected
     * @since 1.5.0
     */
    this.context = (opts.context !== undefined) ? opts.context : null;
};

/**
 * Get the code of the error.
 * @return {String} code
 */
bemap.Error.prototype.getCode = function() {
    return this.code;
};

/**
 * Get the message of the error.
 * @return {String} message
 */
bemap.Error.prototype.getMessage = function() {
    return this.message;
};

/**
 * Get the HTTP status of the error, or null if not HTTP-originated.
 * @return {Number|null} status
 * @since 1.5.0
 */
bemap.Error.prototype.getStatus = function() {
    return this.status;
};

/**
 * Get the request URL associated with the error, or null.
 * @return {String|null} url
 * @since 1.5.0
 */
bemap.Error.prototype.getUrl = function() {
    return this.url;
};

/**
 * Get the free-form context object associated with the error, or null.
 * @return {Object|null} context
 * @since 1.5.0
 */
bemap.Error.prototype.getContext = function() {
    return this.context;
};

/* ============================================================
 * Named error code constants (v1.5.0)
 *
 * Every modernised service in bemap-js-api raises bemap.Error
 * instances with one of these codes. Using the constants keeps
 * call-site code typo-safe.
 * ============================================================ */

bemap.Error.UNAUTHORIZED        = 'UNAUTHORIZED';
bemap.Error.FORBIDDEN           = 'FORBIDDEN';
bemap.Error.RATE_LIMITED        = 'RATE_LIMITED';
bemap.Error.NETWORK             = 'NETWORK';
bemap.Error.ABORTED             = 'ABORTED';
bemap.Error.OFFLINE             = 'OFFLINE';
bemap.Error.INVALID_ARGUMENT    = 'INVALID_ARGUMENT';

bemap.Error.ROUTING_FAILED      = 'ROUTING_FAILED';
bemap.Error.ROUTING_NO_ROUTE    = 'ROUTING_NO_ROUTE';
bemap.Error.ROUTING_TIMEOUT     = 'ROUTING_TIMEOUT';

bemap.Error.EV_FAILED           = 'EV_FAILED';
bemap.Error.EV_NO_JOURNEY       = 'EV_NO_JOURNEY';

bemap.Error.CHARGING_NOT_FOUND  = 'CHARGING_NOT_FOUND';
bemap.Error.CHARGING_TIME_FAILED = 'CHARGING_TIME_FAILED';
bemap.Error.VEHICLE_NOT_FOUND   = 'VEHICLE_NOT_FOUND';
bemap.Error.REACHABLE_AREA_FAILED = 'REACHABLE_AREA_FAILED';

bemap.Error.STYLE_LOAD_FAILED   = 'STYLE_LOAD_FAILED';
bemap.Error.TILE_LOAD_FAILED    = 'TILE_LOAD_FAILED';
bemap.Error.CACHE_HOST_CONFLICT = 'CACHE_HOST_CONFLICT';
bemap.Error.MAPLIBRE_ONLY       = 'MAPLIBRE_ONLY';
bemap.Error.MISSING_DEPENDENCY  = 'MISSING_DEPENDENCY';
bemap.Error.REQUIRES_GLOBE      = 'REQUIRES_GLOBE';