@xh/hoist 76.0.0-SNAPSHOT.1756924112722 → 76.0.0-SNAPSHOT.1756991850787
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/core/exception/Exception.ts +24 -7
- package/package.json +1 -1
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
import {PlainObject, XH} from '@xh/hoist/core';
|
|
8
8
|
import {FetchOptions} from '@xh/hoist/svc';
|
|
9
9
|
import {pluralize} from '@xh/hoist/utils/js';
|
|
10
|
-
import {isPlainObject, truncate} from 'lodash';
|
|
10
|
+
import {isPlainObject, isString, truncate} from 'lodash';
|
|
11
11
|
import {FetchException, HoistException, TimeoutException, TimeoutExceptionConfig} from './Types';
|
|
12
12
|
|
|
13
13
|
/**
|
|
@@ -91,14 +91,13 @@ export class Exception {
|
|
|
91
91
|
try {
|
|
92
92
|
const cType = headers.get('Content-Type');
|
|
93
93
|
if (cType?.includes('application/json')) {
|
|
94
|
-
const
|
|
95
|
-
message = obj ? obj.message : truncate(responseText?.trim(), {length: 255});
|
|
94
|
+
const parsedResp = safeParseJson(responseText);
|
|
96
95
|
return this.createFetchException({
|
|
97
96
|
...defaults,
|
|
98
|
-
name:
|
|
99
|
-
message:
|
|
100
|
-
isRoutine:
|
|
101
|
-
serverDetails:
|
|
97
|
+
name: parsedResp?.name ?? defaults.name,
|
|
98
|
+
message: extractMessage(parsedResp, responseText, statusText),
|
|
99
|
+
isRoutine: parsedResp?.isRoutine ?? false,
|
|
100
|
+
serverDetails: parsedResp ?? responseText
|
|
102
101
|
});
|
|
103
102
|
}
|
|
104
103
|
} catch (ignored) {}
|
|
@@ -234,6 +233,24 @@ function safeParseJson(txt: string): PlainObject {
|
|
|
234
233
|
}
|
|
235
234
|
}
|
|
236
235
|
|
|
236
|
+
function extractMessage(parsedResp: PlainObject, responseText: string, statusText: string): string {
|
|
237
|
+
let ret: string;
|
|
238
|
+
if (parsedResp) {
|
|
239
|
+
// From parsed response, including cause if provided (e.g. ExternalHttpException)
|
|
240
|
+
ret = parsedResp.message;
|
|
241
|
+
if (isString(parsedResp.cause)) {
|
|
242
|
+
const cause = truncate(parsedResp.cause, {length: 255});
|
|
243
|
+
ret = ret ? `${ret} (Caused by: ${cause})` : cause;
|
|
244
|
+
}
|
|
245
|
+
} else {
|
|
246
|
+
// Use raw text if not JSON parseable
|
|
247
|
+
ret = truncate(responseText?.trim(), {length: 255});
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// Fallback to statusText if we have nothing else.
|
|
251
|
+
return ret || statusText;
|
|
252
|
+
}
|
|
253
|
+
|
|
237
254
|
export function isHoistException(src: unknown): src is HoistException {
|
|
238
255
|
return src?.['isHoistException'];
|
|
239
256
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xh/hoist",
|
|
3
|
-
"version": "76.0.0-SNAPSHOT.
|
|
3
|
+
"version": "76.0.0-SNAPSHOT.1756991850787",
|
|
4
4
|
"description": "Hoist add-on for building and deploying React Applications.",
|
|
5
5
|
"repository": "github:xh/hoist-react",
|
|
6
6
|
"homepage": "https://xh.io",
|