@naturalcycles/js-lib 14.172.0 → 14.174.0
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/dist/error/assert.d.ts +0 -4
- package/dist/error/assert.js +7 -14
- package/dist/error/error.util.d.ts +90 -1
- package/dist/error/error.util.js +126 -2
- package/dist/error/try.d.ts +0 -9
- package/dist/error/try.js +6 -19
- package/dist/http/fetcher.d.ts +1 -1
- package/dist/http/fetcher.js +3 -4
- package/dist/index.d.ts +0 -3
- package/dist/index.js +0 -3
- package/dist/promise/pTimeout.d.ts +1 -4
- package/dist/promise/pTimeout.js +2 -9
- package/dist/string/json.util.js +2 -2
- package/dist-esm/error/assert.js +1 -7
- package/dist-esm/error/error.util.js +119 -1
- package/dist-esm/error/try.js +1 -13
- package/dist-esm/http/fetcher.js +2 -3
- package/dist-esm/index.js +0 -3
- package/dist-esm/promise/pTimeout.js +1 -7
- package/dist-esm/string/json.util.js +1 -1
- package/package.json +1 -1
- package/src/error/assert.ts +1 -8
- package/src/error/error.util.ts +180 -1
- package/src/error/try.ts +1 -18
- package/src/http/fetcher.ts +8 -3
- package/src/index.ts +0 -3
- package/src/promise/pTimeout.ts +1 -8
- package/src/string/json.util.ts +1 -1
- package/dist/error/app.error.d.ts +0 -31
- package/dist/error/app.error.js +0 -57
- package/dist/error/httpRequestError.d.ts +0 -28
- package/dist/error/httpRequestError.js +0 -32
- package/dist/error/jsonParseError.d.ts +0 -11
- package/dist/error/jsonParseError.js +0 -14
- package/dist-esm/error/app.error.js +0 -53
- package/dist-esm/error/httpRequestError.js +0 -28
- package/dist-esm/error/jsonParseError.js +0 -10
- package/src/error/app.error.ts +0 -81
- package/src/error/httpRequestError.ts +0 -38
- package/src/error/jsonParseError.ts +0 -20
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { AppError } from './app.error';
|
|
2
|
-
import { ErrorData } from './error.model';
|
|
3
|
-
export interface JsonParseErrorData extends ErrorData {
|
|
4
|
-
/**
|
|
5
|
-
* Original text that failed to get parsed.
|
|
6
|
-
*/
|
|
7
|
-
text?: string;
|
|
8
|
-
}
|
|
9
|
-
export declare class JsonParseError extends AppError<JsonParseErrorData> {
|
|
10
|
-
constructor(data: JsonParseErrorData);
|
|
11
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.JsonParseError = void 0;
|
|
4
|
-
const string_util_1 = require("../string/string.util");
|
|
5
|
-
const app_error_1 = require("./app.error");
|
|
6
|
-
class JsonParseError extends app_error_1.AppError {
|
|
7
|
-
constructor(data) {
|
|
8
|
-
const message = ['Failed to parse', data.text && (0, string_util_1._truncateMiddle)(data.text, 200)]
|
|
9
|
-
.filter(Boolean)
|
|
10
|
-
.join(': ');
|
|
11
|
-
super(message, data, { name: 'JsonParseError' });
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
exports.JsonParseError = JsonParseError;
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Base class for all our (not system) errors.
|
|
3
|
-
*
|
|
4
|
-
* message - "technical" message. Frontend decides to show it or not.
|
|
5
|
-
* data - optional "any" payload.
|
|
6
|
-
* data.userFriendly - if present, will be displayed to the User as is.
|
|
7
|
-
*
|
|
8
|
-
* Based on: https://medium.com/@xpl/javascript-deriving-from-error-properly-8d2f8f315801
|
|
9
|
-
*/
|
|
10
|
-
export class AppError extends Error {
|
|
11
|
-
constructor(message, data = {}, opt = {}) {
|
|
12
|
-
super(message);
|
|
13
|
-
const { name = this.constructor.name, cause } = opt;
|
|
14
|
-
Object.defineProperties(this, {
|
|
15
|
-
name: {
|
|
16
|
-
value: name,
|
|
17
|
-
configurable: true,
|
|
18
|
-
writable: true,
|
|
19
|
-
},
|
|
20
|
-
data: {
|
|
21
|
-
value: data,
|
|
22
|
-
writable: true,
|
|
23
|
-
configurable: true,
|
|
24
|
-
enumerable: false,
|
|
25
|
-
},
|
|
26
|
-
});
|
|
27
|
-
if (cause) {
|
|
28
|
-
Object.defineProperty(this, 'cause', {
|
|
29
|
-
// I'd love to do _anyToError(opt.cause) here, but it causes circular dep ;(
|
|
30
|
-
value: cause,
|
|
31
|
-
writable: true,
|
|
32
|
-
configurable: true,
|
|
33
|
-
enumerable: true, // unlike standard - setting it to true for "visibility"
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
// this is to allow changing this.constuctor.name to a non-minified version
|
|
37
|
-
Object.defineProperty(this.constructor, 'name', {
|
|
38
|
-
value: name,
|
|
39
|
-
configurable: true,
|
|
40
|
-
writable: true,
|
|
41
|
-
});
|
|
42
|
-
// todo: check if it's needed at all!
|
|
43
|
-
// if (Error.captureStackTrace) {
|
|
44
|
-
// Error.captureStackTrace(this, this.constructor)
|
|
45
|
-
// } else {
|
|
46
|
-
// Object.defineProperty(this, 'stack', {
|
|
47
|
-
// value: new Error().stack, // eslint-disable-line unicorn/error-message
|
|
48
|
-
// writable: true,
|
|
49
|
-
// configurable: true,
|
|
50
|
-
// })
|
|
51
|
-
// }
|
|
52
|
-
}
|
|
53
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { AppError } from './app.error';
|
|
2
|
-
/**
|
|
3
|
-
* Error that is thrown when Http Request was made and returned an error.
|
|
4
|
-
* Thrown by, for example, Fetcher.
|
|
5
|
-
*
|
|
6
|
-
* On the Frontend this Error class represents the error when calling the API,
|
|
7
|
-
* contains all the necessary request and response information.
|
|
8
|
-
*
|
|
9
|
-
* On the Backend, similarly, it represents the error when calling some 3rd-party API
|
|
10
|
-
* (backend-to-backend call).
|
|
11
|
-
* On the Backend it often propagates all the way to the Backend error handler,
|
|
12
|
-
* where it would be wrapped in BackendErrorResponseObject.
|
|
13
|
-
*
|
|
14
|
-
* Please note that `ErrorData.backendResponseStatusCode` is NOT exactly the same as
|
|
15
|
-
* `HttpRequestErrorData.responseStatusCode`.
|
|
16
|
-
* E.g 3rd-party call may return 401, but our Backend will still wrap it into an 500 error
|
|
17
|
-
* (by default).
|
|
18
|
-
*/
|
|
19
|
-
export class HttpRequestError extends AppError {
|
|
20
|
-
constructor(message, data, opt) {
|
|
21
|
-
if (data.response) {
|
|
22
|
-
Object.defineProperty(data, 'response', {
|
|
23
|
-
enumerable: false,
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
super(message, data, Object.assign(Object.assign({}, opt), { name: 'HttpRequestError' }));
|
|
27
|
-
}
|
|
28
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { _truncateMiddle } from '../string/string.util';
|
|
2
|
-
import { AppError } from './app.error';
|
|
3
|
-
export class JsonParseError extends AppError {
|
|
4
|
-
constructor(data) {
|
|
5
|
-
const message = ['Failed to parse', data.text && _truncateMiddle(data.text, 200)]
|
|
6
|
-
.filter(Boolean)
|
|
7
|
-
.join(': ');
|
|
8
|
-
super(message, data, { name: 'JsonParseError' });
|
|
9
|
-
}
|
|
10
|
-
}
|
package/src/error/app.error.ts
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import type { ErrorData, ErrorObject } from './error.model'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Base class for all our (not system) errors.
|
|
5
|
-
*
|
|
6
|
-
* message - "technical" message. Frontend decides to show it or not.
|
|
7
|
-
* data - optional "any" payload.
|
|
8
|
-
* data.userFriendly - if present, will be displayed to the User as is.
|
|
9
|
-
*
|
|
10
|
-
* Based on: https://medium.com/@xpl/javascript-deriving-from-error-properly-8d2f8f315801
|
|
11
|
-
*/
|
|
12
|
-
export class AppError<DATA_TYPE extends ErrorData = ErrorData> extends Error {
|
|
13
|
-
data!: DATA_TYPE
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* `cause` here is normalized to be an ErrorObject
|
|
17
|
-
*/
|
|
18
|
-
override cause?: ErrorObject
|
|
19
|
-
|
|
20
|
-
constructor(message: string, data = {} as DATA_TYPE, opt: AppErrorOptions = {}) {
|
|
21
|
-
super(message)
|
|
22
|
-
const { name = this.constructor.name, cause } = opt
|
|
23
|
-
|
|
24
|
-
Object.defineProperties(this, {
|
|
25
|
-
name: {
|
|
26
|
-
value: name,
|
|
27
|
-
configurable: true,
|
|
28
|
-
writable: true,
|
|
29
|
-
},
|
|
30
|
-
data: {
|
|
31
|
-
value: data,
|
|
32
|
-
writable: true,
|
|
33
|
-
configurable: true,
|
|
34
|
-
enumerable: false,
|
|
35
|
-
},
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
if (cause) {
|
|
39
|
-
Object.defineProperty(this, 'cause', {
|
|
40
|
-
// I'd love to do _anyToError(opt.cause) here, but it causes circular dep ;(
|
|
41
|
-
value: cause,
|
|
42
|
-
writable: true,
|
|
43
|
-
configurable: true,
|
|
44
|
-
enumerable: true, // unlike standard - setting it to true for "visibility"
|
|
45
|
-
})
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// this is to allow changing this.constuctor.name to a non-minified version
|
|
49
|
-
Object.defineProperty(this.constructor, 'name', {
|
|
50
|
-
value: name,
|
|
51
|
-
configurable: true,
|
|
52
|
-
writable: true,
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
// todo: check if it's needed at all!
|
|
56
|
-
// if (Error.captureStackTrace) {
|
|
57
|
-
// Error.captureStackTrace(this, this.constructor)
|
|
58
|
-
// } else {
|
|
59
|
-
// Object.defineProperty(this, 'stack', {
|
|
60
|
-
// value: new Error().stack, // eslint-disable-line unicorn/error-message
|
|
61
|
-
// writable: true,
|
|
62
|
-
// configurable: true,
|
|
63
|
-
// })
|
|
64
|
-
// }
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Extra options for AppError constructor.
|
|
70
|
-
*/
|
|
71
|
-
export interface AppErrorOptions {
|
|
72
|
-
/**
|
|
73
|
-
* Overrides Error.name and Error.constructor.name
|
|
74
|
-
*/
|
|
75
|
-
name?: string
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Sets Error.cause
|
|
79
|
-
*/
|
|
80
|
-
cause?: ErrorObject
|
|
81
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { AppError, AppErrorOptions } from './app.error'
|
|
2
|
-
import type { ErrorObject, HttpRequestErrorData } from './error.model'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Error that is thrown when Http Request was made and returned an error.
|
|
6
|
-
* Thrown by, for example, Fetcher.
|
|
7
|
-
*
|
|
8
|
-
* On the Frontend this Error class represents the error when calling the API,
|
|
9
|
-
* contains all the necessary request and response information.
|
|
10
|
-
*
|
|
11
|
-
* On the Backend, similarly, it represents the error when calling some 3rd-party API
|
|
12
|
-
* (backend-to-backend call).
|
|
13
|
-
* On the Backend it often propagates all the way to the Backend error handler,
|
|
14
|
-
* where it would be wrapped in BackendErrorResponseObject.
|
|
15
|
-
*
|
|
16
|
-
* Please note that `ErrorData.backendResponseStatusCode` is NOT exactly the same as
|
|
17
|
-
* `HttpRequestErrorData.responseStatusCode`.
|
|
18
|
-
* E.g 3rd-party call may return 401, but our Backend will still wrap it into an 500 error
|
|
19
|
-
* (by default).
|
|
20
|
-
*/
|
|
21
|
-
export class HttpRequestError extends AppError<HttpRequestErrorData> {
|
|
22
|
-
constructor(message: string, data: HttpRequestErrorData, opt?: AppErrorOptions) {
|
|
23
|
-
if (data.response) {
|
|
24
|
-
Object.defineProperty(data, 'response', {
|
|
25
|
-
enumerable: false,
|
|
26
|
-
})
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
super(message, data, { ...opt, name: 'HttpRequestError' })
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Cause is strictly-defined for HttpRequestError,
|
|
34
|
-
* so it always has a cause.
|
|
35
|
-
* (for dev convenience)
|
|
36
|
-
*/
|
|
37
|
-
override cause!: ErrorObject
|
|
38
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { _truncateMiddle } from '../string/string.util'
|
|
2
|
-
import { AppError } from './app.error'
|
|
3
|
-
import { ErrorData } from './error.model'
|
|
4
|
-
|
|
5
|
-
export interface JsonParseErrorData extends ErrorData {
|
|
6
|
-
/**
|
|
7
|
-
* Original text that failed to get parsed.
|
|
8
|
-
*/
|
|
9
|
-
text?: string
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export class JsonParseError extends AppError<JsonParseErrorData> {
|
|
13
|
-
constructor(data: JsonParseErrorData) {
|
|
14
|
-
const message = ['Failed to parse', data.text && _truncateMiddle(data.text, 200)]
|
|
15
|
-
.filter(Boolean)
|
|
16
|
-
.join(': ')
|
|
17
|
-
|
|
18
|
-
super(message, data, { name: 'JsonParseError' })
|
|
19
|
-
}
|
|
20
|
-
}
|