@xh/hoist 73.0.0-SNAPSHOT.1741714715638 → 73.0.0-SNAPSHOT.1741787114903

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/CHANGELOG.md CHANGED
@@ -7,6 +7,10 @@
7
7
  * Modify `TabContainerModel` to make more methods `protected`, improving extensibility for advanced
8
8
  use-cases.
9
9
 
10
+ * Enhance exception handling in `FetchService` to capture messages returned as raw strings, or without
11
+ explicit names.
12
+
13
+
10
14
  ## v72.1.0 - 2025-02-13
11
15
 
12
16
  ### 🎁 New Features
@@ -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} from 'lodash';
10
+ import {isPlainObject, truncate} from 'lodash';
11
11
  import {FetchException, HoistException, TimeoutException, TimeoutExceptionConfig} from './Types';
12
12
 
13
13
  /**
@@ -90,17 +90,16 @@ export class Exception {
90
90
  // Try to "smart" decode as server provided JSON Exception (with a name)
91
91
  try {
92
92
  const cType = headers.get('Content-Type');
93
- if (cType && cType.includes('application/json')) {
94
- const serverDetails = JSON.parse(responseText);
95
- if (serverDetails?.name) {
96
- return this.createFetchException({
97
- ...defaults,
98
- name: serverDetails.name,
99
- message: serverDetails.message,
100
- isRoutine: serverDetails.isRoutine ?? false,
101
- serverDetails
102
- });
103
- }
93
+ if (cType?.includes('application/json')) {
94
+ const obj = safeParseJson(responseText),
95
+ message = obj ? obj.message : truncate(responseText?.trim(), {length: 255});
96
+ return this.createFetchException({
97
+ ...defaults,
98
+ name: obj?.name ?? defaults.name,
99
+ message: message ?? statusText,
100
+ isRoutine: obj?.isRoutine ?? false,
101
+ serverDetails: obj ?? responseText
102
+ });
104
103
  }
105
104
  } catch (ignored) {}
106
105
 
@@ -222,6 +221,14 @@ export class Exception {
222
221
  }
223
222
  }
224
223
 
224
+ function safeParseJson(txt: string): PlainObject {
225
+ try {
226
+ return JSON.parse(txt);
227
+ } catch (ignored) {
228
+ return null;
229
+ }
230
+ }
231
+
225
232
  export function isHoistException(src: unknown): src is HoistException {
226
233
  return src?.['isHoistException'];
227
234
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xh/hoist",
3
- "version": "73.0.0-SNAPSHOT.1741714715638",
3
+ "version": "73.0.0-SNAPSHOT.1741787114903",
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",