@dxos/errors 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +8 -0
- package/dist/src/errors.d.ts +29 -0
- package/dist/src/errors.d.ts.map +1 -0
- package/dist/src/errors.js +46 -0
- package/dist/src/errors.js.map +1 -0
- package/dist/src/errors.test.d.ts +2 -0
- package/dist/src/errors.test.d.ts.map +1 -0
- package/dist/src/errors.test.js +44 -0
- package/dist/src/errors.test.js.map +1 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +21 -0
- package/dist/src/index.js.map +1 -0
- package/package.json +28 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
Copyright (c) 2022 DXOS
|
|
3
|
+
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
5
|
+
|
|
6
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
7
|
+
|
|
8
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NOTE: Messages should be sentences (Start with a capital letter and end with a period).
|
|
3
|
+
* Errors can optionally include a JSON context object.
|
|
4
|
+
*/
|
|
5
|
+
declare class BaseError extends Error {
|
|
6
|
+
readonly code: string;
|
|
7
|
+
readonly context?: any;
|
|
8
|
+
constructor(code: string, message?: string, context?: any);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* User facing API Errors.
|
|
12
|
+
* E.g., something was misconfigured.
|
|
13
|
+
*/
|
|
14
|
+
export declare class ApiError extends BaseError {
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Internal system errors.
|
|
18
|
+
* E.g., unexpected/unrecoverable runtime error.
|
|
19
|
+
*/
|
|
20
|
+
export declare class SystemError extends BaseError {
|
|
21
|
+
}
|
|
22
|
+
export declare class InvalidConfigError extends ApiError {
|
|
23
|
+
constructor(message: string, context?: any);
|
|
24
|
+
}
|
|
25
|
+
export declare class RemoteServiceConnectionTimeout extends ApiError {
|
|
26
|
+
constructor(message?: string, context?: any);
|
|
27
|
+
}
|
|
28
|
+
export {};
|
|
29
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,cAAM,SAAU,SAAQ,KAAK;IACf,QAAQ,CAAC,IAAI,EAAE,MAAM;IAAoB,QAAQ,CAAC,OAAO,CAAC;gBAAjD,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,EAAW,OAAO,CAAC,KAAK;CAK5E;AAED;;;GAGG;AACH,qBAAa,QAAS,SAAQ,SAAS;CAAG;AAE1C;;;GAGG;AACH,qBAAa,WAAY,SAAQ,SAAS;CAAG;AAE7C,qBAAa,kBAAmB,SAAQ,QAAQ;gBAClC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG;CAG3C;AAED,qBAAa,8BAA+B,SAAQ,QAAQ;gBAC9C,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG;CAG5C"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
//
|
|
3
|
+
// Copyright 2021 DXOS.org
|
|
4
|
+
//
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.RemoteServiceConnectionTimeout = exports.InvalidConfigError = exports.SystemError = exports.ApiError = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* NOTE: Messages should be sentences (Start with a capital letter and end with a period).
|
|
9
|
+
* Errors can optionally include a JSON context object.
|
|
10
|
+
*/
|
|
11
|
+
class BaseError extends Error {
|
|
12
|
+
constructor(code, message, context) {
|
|
13
|
+
super(message ? `${code}: ${message}` : code.toString());
|
|
14
|
+
this.code = code;
|
|
15
|
+
this.context = context;
|
|
16
|
+
// NOTE: Restores prototype chain (https://stackoverflow.com/a/48342359).
|
|
17
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* User facing API Errors.
|
|
22
|
+
* E.g., something was misconfigured.
|
|
23
|
+
*/
|
|
24
|
+
class ApiError extends BaseError {
|
|
25
|
+
}
|
|
26
|
+
exports.ApiError = ApiError;
|
|
27
|
+
/**
|
|
28
|
+
* Internal system errors.
|
|
29
|
+
* E.g., unexpected/unrecoverable runtime error.
|
|
30
|
+
*/
|
|
31
|
+
class SystemError extends BaseError {
|
|
32
|
+
}
|
|
33
|
+
exports.SystemError = SystemError;
|
|
34
|
+
class InvalidConfigError extends ApiError {
|
|
35
|
+
constructor(message, context) {
|
|
36
|
+
super('INVALID_CONFIG', message, context);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.InvalidConfigError = InvalidConfigError;
|
|
40
|
+
class RemoteServiceConnectionTimeout extends ApiError {
|
|
41
|
+
constructor(message, context) {
|
|
42
|
+
super('REMOTE_SERVICE_CONNECTION_TIMEOUT', message, context);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.RemoteServiceConnectionTimeout = RemoteServiceConnectionTimeout;
|
|
46
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;AAEF;;;GAGG;AACH,MAAM,SAAU,SAAQ,KAAK;IAC3B,YAAqB,IAAY,EAAE,OAAgB,EAAW,OAAa;QACzE,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,KAAK,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;QADtC,SAAI,GAAJ,IAAI,CAAQ;QAA6B,YAAO,GAAP,OAAO,CAAM;QAEzE,yEAAyE;QACzE,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACpD,CAAC;CACF;AAED;;;GAGG;AACH,MAAa,QAAS,SAAQ,SAAS;CAAG;AAA1C,4BAA0C;AAE1C;;;GAGG;AACH,MAAa,WAAY,SAAQ,SAAS;CAAG;AAA7C,kCAA6C;AAE7C,MAAa,kBAAmB,SAAQ,QAAQ;IAC9C,YAAY,OAAe,EAAE,OAAa;QACxC,KAAK,CAAC,gBAAgB,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IAC5C,CAAC;CACF;AAJD,gDAIC;AAED,MAAa,8BAA+B,SAAQ,QAAQ;IAC1D,YAAY,OAAgB,EAAE,OAAa;QACzC,KAAK,CAAC,mCAAmC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IAC/D,CAAC;CACF;AAJD,wEAIC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.test.d.ts","sourceRoot":"","sources":["../../src/errors.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
//
|
|
3
|
+
// Copyright 2022 DXOS.org
|
|
4
|
+
//
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
17
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
18
|
+
}) : function(o, v) {
|
|
19
|
+
o["default"] = v;
|
|
20
|
+
});
|
|
21
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
22
|
+
if (mod && mod.__esModule) return mod;
|
|
23
|
+
var result = {};
|
|
24
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
25
|
+
__setModuleDefault(result, mod);
|
|
26
|
+
return result;
|
|
27
|
+
};
|
|
28
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
29
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
30
|
+
};
|
|
31
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
+
const chai_1 = __importStar(require("chai"));
|
|
33
|
+
const chai_as_promised_1 = __importDefault(require("chai-as-promised"));
|
|
34
|
+
const errors_1 = require("./errors");
|
|
35
|
+
chai_1.default.use(chai_as_promised_1.default);
|
|
36
|
+
describe('Errors', function () {
|
|
37
|
+
it('test', async function () {
|
|
38
|
+
const runTest = async () => {
|
|
39
|
+
throw new errors_1.ApiError('Test error');
|
|
40
|
+
};
|
|
41
|
+
await (0, chai_1.expect)(runTest()).to.be.rejectedWith('Test error');
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
//# sourceMappingURL=errors.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.test.js","sourceRoot":"","sources":["../../src/errors.test.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEF,6CAAoC;AACpC,wEAA8C;AAE9C,qCAAoC;AAEpC,cAAI,CAAC,GAAG,CAAC,0BAAc,CAAC,CAAC;AAEzB,QAAQ,CAAC,QAAQ,EAAE;IACjB,EAAE,CAAC,MAAM,EAAE,KAAK;QACd,MAAM,OAAO,GAAG,KAAK,IAAI,EAAE;YACzB,MAAM,IAAI,iBAAQ,CAAC,YAAY,CAAC,CAAC;QACnC,CAAC,CAAC;QAEF,MAAM,IAAA,aAAM,EAAC,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;IAC3D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
//
|
|
3
|
+
// Copyright 2022 DXOS.org
|
|
4
|
+
//
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
17
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
__exportStar(require("./errors"), exports);
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;;;;;;;;;;;;;;AAEF,2CAAyB"}
|
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dxos/errors",
|
|
3
|
+
"version": "0.1.9",
|
|
4
|
+
"description": "Error definitions and utilities",
|
|
5
|
+
"homepage": "https://dxos.org",
|
|
6
|
+
"bugs": "https://github.com/dxos/dxos/issues",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"author": "DXOS.org",
|
|
9
|
+
"main": "dist/src/index.js",
|
|
10
|
+
"browser": {
|
|
11
|
+
"node:assert": "assert"
|
|
12
|
+
},
|
|
13
|
+
"types": "dist/src/index.d.ts",
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"esbuild-plugin.js",
|
|
17
|
+
"rollup-plugin.js",
|
|
18
|
+
"webpack-plugin.js"
|
|
19
|
+
],
|
|
20
|
+
"dependencies": {},
|
|
21
|
+
"devDependencies": {},
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public"
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"check": "true"
|
|
27
|
+
}
|
|
28
|
+
}
|