UNPKG

@hms-networks/kolibri-js-client

Version:

Kolibri Consumer API client for building kolibri based applications

262 lines 10.3 kB
/* * Copyright 2021 HMS Industrial Networks AB * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http: //www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var KolibriRequestError = /** @class */ (function (_super) { __extends(KolibriRequestError, _super); function KolibriRequestError(message, data) { var _newTarget = this.constructor; var _this = _super.call(this, message) || this; if (data) { _this.data = data; } Object.setPrototypeOf(_this, _newTarget.prototype); _this.name = _this.constructor.name; return _this; } return KolibriRequestError; }(Error)); export { KolibriRequestError }; var GeneralError = /** @class */ (function (_super) { __extends(GeneralError, _super); function GeneralError(data) { return _super.call(this, 'General request error', data) || this; } return GeneralError; }(KolibriRequestError)); export { GeneralError }; var InvalidOpCodeError = /** @class */ (function (_super) { __extends(InvalidOpCodeError, _super); function InvalidOpCodeError(data) { return _super.call(this, 'Invalid op code error', data) || this; } return InvalidOpCodeError; }(KolibriRequestError)); export { InvalidOpCodeError }; var InvalidOptionError = /** @class */ (function (_super) { __extends(InvalidOptionError, _super); function InvalidOptionError(data) { return _super.call(this, 'Invalid option error', data) || this; } return InvalidOptionError; }(KolibriRequestError)); export { InvalidOptionError }; var InvalidProtocolVersionError = /** @class */ (function (_super) { __extends(InvalidProtocolVersionError, _super); function InvalidProtocolVersionError(data) { return _super.call(this, 'Invalid protocol version error', data) || this; } return InvalidProtocolVersionError; }(KolibriRequestError)); export { InvalidProtocolVersionError }; var AccessDeniedError = /** @class */ (function (_super) { __extends(AccessDeniedError, _super); function AccessDeniedError(data) { return _super.call(this, 'Access denied error', data) || this; } return AccessDeniedError; }(KolibriRequestError)); export { AccessDeniedError }; var InvalidPathError = /** @class */ (function (_super) { __extends(InvalidPathError, _super); function InvalidPathError(data) { return _super.call(this, 'Invalid path error', data) || this; } return InvalidPathError; }(KolibriRequestError)); export { InvalidPathError }; var InvalidNodeTypeError = /** @class */ (function (_super) { __extends(InvalidNodeTypeError, _super); function InvalidNodeTypeError(data) { return _super.call(this, 'Invalid node type error', data) || this; } return InvalidNodeTypeError; }(KolibriRequestError)); export { InvalidNodeTypeError }; var InvalidNodeIndexError = /** @class */ (function (_super) { __extends(InvalidNodeIndexError, _super); function InvalidNodeIndexError(data) { return _super.call(this, 'Invalid node index error', data) || this; } return InvalidNodeIndexError; }(KolibriRequestError)); export { InvalidNodeIndexError }; var InvalidNodePropertyError = /** @class */ (function (_super) { __extends(InvalidNodePropertyError, _super); function InvalidNodePropertyError(data) { return _super.call(this, 'Invalid node property error', data) || this; } return InvalidNodePropertyError; }(KolibriRequestError)); export { InvalidNodePropertyError }; var InvalidNodeStateError = /** @class */ (function (_super) { __extends(InvalidNodeStateError, _super); function InvalidNodeStateError(data) { return _super.call(this, 'Invalid node state error', data) || this; } return InvalidNodeStateError; }(KolibriRequestError)); export { InvalidNodeStateError }; var InvalidSequenceNumberError = /** @class */ (function (_super) { __extends(InvalidSequenceNumberError, _super); function InvalidSequenceNumberError(data) { return _super.call(this, 'Invalid sequence number error', data) || this; } return InvalidSequenceNumberError; }(KolibriRequestError)); export { InvalidSequenceNumberError }; var InvalidDataTypeError = /** @class */ (function (_super) { __extends(InvalidDataTypeError, _super); function InvalidDataTypeError(data) { return _super.call(this, 'Invalid data type error', data) || this; } return InvalidDataTypeError; }(KolibriRequestError)); export { InvalidDataTypeError }; var InvalidRecipientError = /** @class */ (function (_super) { __extends(InvalidRecipientError, _super); function InvalidRecipientError(data) { return _super.call(this, 'Invalid recipient error', data) || this; } return InvalidRecipientError; }(KolibriRequestError)); export { InvalidRecipientError }; var InvalidProtocolError = /** @class */ (function (_super) { __extends(InvalidProtocolError, _super); function InvalidProtocolError(data) { return _super.call(this, 'Invalid protocol error', data) || this; } return InvalidProtocolError; }(KolibriRequestError)); export { InvalidProtocolError }; var MissingParameterError = /** @class */ (function (_super) { __extends(MissingParameterError, _super); function MissingParameterError(data) { return _super.call(this, 'Missing parameter error', data) || this; } return MissingParameterError; }(KolibriRequestError)); export { MissingParameterError }; var InvalidParameterError = /** @class */ (function (_super) { __extends(InvalidParameterError, _super); function InvalidParameterError(data) { return _super.call(this, 'Invalid parameter error', data) || this; } return InvalidParameterError; }(KolibriRequestError)); export { InvalidParameterError }; var InvalidValueError = /** @class */ (function (_super) { __extends(InvalidValueError, _super); function InvalidValueError(data) { return _super.call(this, 'Invalid value error', data) || this; } return InvalidValueError; }(KolibriRequestError)); export { InvalidValueError }; var ItemNotFoundError = /** @class */ (function (_super) { __extends(ItemNotFoundError, _super); function ItemNotFoundError(data) { return _super.call(this, 'Item not found error', data) || this; } return ItemNotFoundError; }(KolibriRequestError)); export { ItemNotFoundError }; var ItemExistsError = /** @class */ (function (_super) { __extends(ItemExistsError, _super); function ItemExistsError(data) { return _super.call(this, 'Item exists error', data) || this; } return ItemExistsError; }(KolibriRequestError)); export { ItemExistsError }; var RateLimitExceededError = /** @class */ (function (_super) { __extends(RateLimitExceededError, _super); function RateLimitExceededError(data) { return _super.call(this, 'Rate limit exceeded error', data) || this; } return RateLimitExceededError; }(KolibriRequestError)); export { RateLimitExceededError }; var QueueSizeLimitExceededError = /** @class */ (function (_super) { __extends(QueueSizeLimitExceededError, _super); function QueueSizeLimitExceededError(data) { return _super.call(this, 'Queue size limit exceeded error', data) || this; } return QueueSizeLimitExceededError; }(KolibriRequestError)); export { QueueSizeLimitExceededError }; export function getRequestError(code, data) { switch (code) { case -31901: return new GeneralError(data); case -31902: return new InvalidOpCodeError(data); case -31903: return new InvalidOptionError(data); case -31904: return new InvalidProtocolVersionError(data); case -31905: return new AccessDeniedError(data); case -31906: return new InvalidPathError(data); case -31907: return new InvalidNodeTypeError(data); case -31908: return new InvalidNodeIndexError(data); case -31909: return new InvalidNodePropertyError(data); case -31910: return new InvalidNodeStateError(data); case -31911: return new InvalidSequenceNumberError(data); case -31912: return new InvalidDataTypeError(data); case -31913: return new InvalidRecipientError(data); case -31914: return new InvalidProtocolError(data); case -31915: return new MissingParameterError(data); case -31916: return new InvalidParameterError(data); case -31917: return new InvalidValueError(data); case -31918: return new ItemNotFoundError(data); case -31919: return new ItemExistsError(data); case -31920: return new RateLimitExceededError(data); case -31921: return new QueueSizeLimitExceededError(data); default: return new KolibriRequestError('Unknown request error'); } } //# sourceMappingURL=kolibri_request_error.js.map