@hexdspace/react 0.0.23 → 0.0.26

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/index.d.ts CHANGED
@@ -177,7 +177,9 @@ interface GenericResponse {
177
177
  }
178
178
 
179
179
  interface ErrorResponse {
180
- error: string;
180
+ message: string;
181
+ status: number;
182
+ name: string;
181
183
  details?: unknown;
182
184
  }
183
185
 
package/dist/index.js CHANGED
@@ -522,7 +522,11 @@ var FetchHttpClient = class {
522
522
  signal: config?.signal
523
523
  });
524
524
  const data = await (res.headers.get("content-type")?.includes("application/json") ? res.json() : res.text());
525
- if (!res.ok) throw new HttpError(res.statusText, res.status, data);
525
+ if (!res.ok) {
526
+ const errorResponse = data;
527
+ const message = errorResponse?.message ?? res.statusText;
528
+ throw new HttpError(message, res.status, errorResponse);
529
+ }
526
530
  return {
527
531
  data,
528
532
  status: res.status,
@@ -531,7 +535,11 @@ var FetchHttpClient = class {
531
535
  } catch (err) {
532
536
  if (err instanceof HttpError) throw err;
533
537
  const message = err instanceof Error ? err.message : "HTTP request failed";
534
- throw new HttpError(message, 0, { error: JSON.stringify(err) });
538
+ throw new HttpError(message, 0, {
539
+ name: "Error",
540
+ message: JSON.stringify(err),
541
+ status: 500
542
+ });
535
543
  }
536
544
  }
537
545
  resolve(url) {
@@ -546,7 +554,11 @@ async function refresh(httpClient2) {
546
554
  if (err instanceof HttpError) {
547
555
  return nok(err);
548
556
  } else {
549
- return nok(new HttpError("Unknown error during refresh", 0, { error: JSON.stringify(err) }));
557
+ return nok(new HttpError("Unknown error during refresh", 0, {
558
+ name: "Error",
559
+ message: JSON.stringify(err),
560
+ status: 500
561
+ }));
550
562
  }
551
563
  }
552
564
  }
@@ -856,15 +868,21 @@ function dispatchLoginResult(res, dispatch) {
856
868
  if (res.ok) {
857
869
  dispatch({ type: "COMPLETE", user: res.value });
858
870
  } else {
859
- dispatch({ type: "FAILED", error: res.error.message });
871
+ dispatch({ type: "FAILED", error: getErrorMessage(res.error) });
860
872
  }
861
873
  }
862
874
  function dispatchRegisterResult(res, dispatch) {
863
875
  if (res.ok) {
864
876
  dispatch({ type: "SUCCESS", message: res.value.message });
865
877
  } else {
866
- dispatch({ type: "FAILED", error: res.error.message });
878
+ dispatch({ type: "FAILED", error: getErrorMessage(res.error) });
879
+ }
880
+ }
881
+ function getErrorMessage(error) {
882
+ if (error instanceof HttpError) {
883
+ return error.response.message;
867
884
  }
885
+ return error.message;
868
886
  }
869
887
 
870
888
  // src/feature/auth/interface/web/react/hook/useAuthedUser.tsx
@@ -963,7 +981,7 @@ function httpResponse(data, status = 200) {
963
981
  return { data, status, headers: {} };
964
982
  }
965
983
  function unauthorized() {
966
- return new HttpError("Unauthorized", 401, { error: "Unauthorized" });
984
+ return new HttpError("Unauthorized", 401, { message: "Unauthorized", status: 401, name: "Unauthorized" });
967
985
  }
968
986
  var MockAuthHttpClient = class extends MockHttpClient {
969
987
  fixtures;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hexdspace/react",
3
- "version": "0.0.23",
3
+ "version": "0.0.26",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",