@hexdspace/react 0.0.22 → 0.0.25

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.
Files changed (2) hide show
  1. package/dist/index.js +16 -9
  2. package/package.json +1 -1
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?.error ?? res.statusText;
528
+ throw new HttpError(message, res.status, errorResponse);
529
+ }
526
530
  return {
527
531
  data,
528
532
  status: res.status,
@@ -856,16 +860,22 @@ function dispatchLoginResult(res, dispatch) {
856
860
  if (res.ok) {
857
861
  dispatch({ type: "COMPLETE", user: res.value });
858
862
  } else {
859
- dispatch({ type: "FAILED", error: res.error.message });
863
+ dispatch({ type: "FAILED", error: getErrorMessage(res.error) });
860
864
  }
861
865
  }
862
866
  function dispatchRegisterResult(res, dispatch) {
863
867
  if (res.ok) {
864
868
  dispatch({ type: "SUCCESS", message: res.value.message });
865
869
  } else {
866
- dispatch({ type: "FAILED", error: res.error.message });
870
+ dispatch({ type: "FAILED", error: getErrorMessage(res.error) });
867
871
  }
868
872
  }
873
+ function getErrorMessage(error) {
874
+ if (error instanceof HttpError) {
875
+ return error.response.error ?? error.message;
876
+ }
877
+ return error.message;
878
+ }
869
879
 
870
880
  // src/feature/auth/interface/web/react/hook/useAuthedUser.tsx
871
881
  function useAuthedUser() {
@@ -925,7 +935,7 @@ function RequireAuth({
925
935
  return /* @__PURE__ */ jsx6(Fragment, { children: loadingPlaceholder ?? null });
926
936
  }
927
937
  if (auth.status === "error") {
928
- return /* @__PURE__ */ jsx6(Fragment, { children: errorPlaceholder ?? unauthenticatedPlaceholder ?? loadingPlaceholder ?? null });
938
+ return /* @__PURE__ */ jsx6(Fragment, { children: errorPlaceholder ?? null });
929
939
  }
930
940
  if (auth.status === "unauthenticated") {
931
941
  if (unauthenticatedRedirectTo) {
@@ -947,16 +957,13 @@ function RedirectIfAuthed({
947
957
  return /* @__PURE__ */ jsx6(Fragment, { children: loadingPlaceholder ?? null });
948
958
  }
949
959
  if (auth.status === "error") {
950
- return /* @__PURE__ */ jsx6(Fragment, { children: errorPlaceholder ?? nonAuthedPlaceholder ?? loadingPlaceholder ?? null });
960
+ return /* @__PURE__ */ jsx6(Fragment, { children: errorPlaceholder ?? loadingPlaceholder ?? null });
951
961
  }
952
962
  if (auth.status === "authenticated") {
953
963
  if (redirectTo) {
954
964
  return /* @__PURE__ */ jsx6(Navigate, { to: redirectTo, replace: true });
955
965
  }
956
- if (authenticatedPlaceholder) {
957
- return /* @__PURE__ */ jsx6(Fragment, { children: authenticatedPlaceholder });
958
- }
959
- return /* @__PURE__ */ jsx6(Outlet, {});
966
+ return /* @__PURE__ */ jsx6(Fragment, { children: authenticatedPlaceholder ?? null });
960
967
  }
961
968
  return nonAuthedPlaceholder ? /* @__PURE__ */ jsx6(Fragment, { children: nonAuthedPlaceholder }) : /* @__PURE__ */ jsx6(Outlet, {});
962
969
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hexdspace/react",
3
- "version": "0.0.22",
3
+ "version": "0.0.25",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",