@riocrypto/common-server 1.0.2643 → 1.0.2644
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.
|
@@ -19,65 +19,69 @@ function isCustomError(error) {
|
|
|
19
19
|
}
|
|
20
20
|
function extractErrorMessage(error, defaultMessage = "An unknown error occurred") {
|
|
21
21
|
var _a, _b;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (typeof error === "string") {
|
|
26
|
-
return error || defaultMessage;
|
|
27
|
-
}
|
|
28
|
-
if (isCustomError(error)) {
|
|
29
|
-
const serialized = error.serializeErrors();
|
|
30
|
-
if (serialized.length > 0) {
|
|
31
|
-
return serialized.map((e) => e.message).join(", ");
|
|
22
|
+
try {
|
|
23
|
+
if (error === null || error === undefined) {
|
|
24
|
+
return defaultMessage;
|
|
32
25
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
if (
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
.
|
|
42
|
-
.filter(Boolean);
|
|
26
|
+
if (typeof error === "string") {
|
|
27
|
+
return error || defaultMessage;
|
|
28
|
+
}
|
|
29
|
+
if (isCustomError(error)) {
|
|
30
|
+
const serialized = error.serializeErrors();
|
|
31
|
+
if ((serialized === null || serialized === void 0 ? void 0 : serialized.length) > 0) {
|
|
32
|
+
const messages = serialized
|
|
33
|
+
.map((e) => e === null || e === void 0 ? void 0 : e.message)
|
|
34
|
+
.filter((m) => typeof m === "string" && m.length > 0);
|
|
43
35
|
if (messages.length > 0) {
|
|
44
36
|
return messages.join(", ");
|
|
45
37
|
}
|
|
46
38
|
}
|
|
47
|
-
|
|
48
|
-
|
|
39
|
+
return error.message || defaultMessage;
|
|
40
|
+
}
|
|
41
|
+
if (isAxiosLikeError(error)) {
|
|
42
|
+
const responseData = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data;
|
|
43
|
+
if (responseData) {
|
|
44
|
+
if (Array.isArray(responseData.errors) && responseData.errors.length > 0) {
|
|
45
|
+
const messages = responseData.errors
|
|
46
|
+
.map((e) => e === null || e === void 0 ? void 0 : e.message)
|
|
47
|
+
.filter((m) => typeof m === "string" && m.length > 0);
|
|
48
|
+
if (messages.length > 0) {
|
|
49
|
+
return messages.join(", ");
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (typeof responseData.error === "string" && responseData.error) {
|
|
53
|
+
return responseData.error;
|
|
54
|
+
}
|
|
55
|
+
if (typeof responseData.message === "string" && responseData.message) {
|
|
56
|
+
return responseData.message;
|
|
57
|
+
}
|
|
58
|
+
if (typeof responseData === "string" && responseData) {
|
|
59
|
+
return responseData;
|
|
60
|
+
}
|
|
49
61
|
}
|
|
50
|
-
if (
|
|
51
|
-
return
|
|
62
|
+
if (error.message) {
|
|
63
|
+
return error.message;
|
|
52
64
|
}
|
|
53
|
-
if (
|
|
54
|
-
return
|
|
65
|
+
if ((_b = error.response) === null || _b === void 0 ? void 0 : _b.statusText) {
|
|
66
|
+
return `HTTP ${error.response.status}: ${error.response.statusText}`;
|
|
55
67
|
}
|
|
56
68
|
}
|
|
57
|
-
if (error
|
|
58
|
-
return error.message;
|
|
69
|
+
if (error instanceof Error) {
|
|
70
|
+
return error.message || defaultMessage;
|
|
59
71
|
}
|
|
60
|
-
if ((
|
|
61
|
-
return
|
|
72
|
+
if (isErrorWithMessage(error)) {
|
|
73
|
+
return error.message || defaultMessage;
|
|
62
74
|
}
|
|
63
|
-
|
|
64
|
-
if (error instanceof Error) {
|
|
65
|
-
return error.message || defaultMessage;
|
|
66
|
-
}
|
|
67
|
-
if (isErrorWithMessage(error)) {
|
|
68
|
-
return error.message || defaultMessage;
|
|
69
|
-
}
|
|
70
|
-
if (typeof error === "object") {
|
|
71
|
-
try {
|
|
75
|
+
if (typeof error === "object") {
|
|
72
76
|
const stringified = JSON.stringify(error);
|
|
73
77
|
if (stringified && stringified !== "{}") {
|
|
74
78
|
return stringified;
|
|
75
79
|
}
|
|
76
80
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
81
|
+
return String(error) || defaultMessage;
|
|
82
|
+
}
|
|
83
|
+
catch (_c) {
|
|
84
|
+
return defaultMessage;
|
|
80
85
|
}
|
|
81
|
-
return String(error) || defaultMessage;
|
|
82
86
|
}
|
|
83
87
|
exports.extractErrorMessage = extractErrorMessage;
|