shelflife-react-hooks 1.0.9 → 1.0.10

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shelflife-react-hooks",
3
- "version": "1.0.9",
3
+ "version": "1.0.10",
4
4
  "description": "",
5
5
  "license": "ISC",
6
6
  "author": "Preisler25",
@@ -87,7 +87,6 @@ export const signupRequest = async (
87
87
  throw new Error('Signup response missing user');
88
88
  }
89
89
 
90
- config.setUser(payload);
91
90
  return payload;
92
91
  });
93
92
 
@@ -1,5 +1,6 @@
1
1
  import type { ShoppingListItem } from '../../type/models.js';
2
2
  import type { CreateShoppingItemRequest, EditShoppingItemRequest } from '../../type/requests.js';
3
+ import type { CreateShoppingItemError, EditShoppingItemError } from '../../type/shoppingList.js';
3
4
  import { buildAuthHeaders, normalizeBaseUrl, readJson } from '../http.js';
4
5
  import { runWithRequestState, type RequestStateHandlers } from './requestState.js';
5
6
 
@@ -55,6 +56,11 @@ export const createShoppingItemRequest = async (
55
56
  });
56
57
 
57
58
  if (!response.ok) {
59
+ const err = await readJson<CreateShoppingItemError>(response);
60
+
61
+ if (err?.productId || err?.amountToBuy)
62
+ throw err;
63
+
58
64
  throw new Error('Failed to create shopping list item');
59
65
  }
60
66
 
@@ -82,6 +88,11 @@ export const editShoppingItemRequest = async (
82
88
  });
83
89
 
84
90
  if (!response.ok) {
91
+ const err = await readJson<EditShoppingItemError>(response);
92
+
93
+ if (err?.productId || err?.amountToBuy)
94
+ throw err;
95
+
85
96
  throw new Error('Failed to edit shopping list item');
86
97
  }
87
98
 
@@ -0,0 +1,14 @@
1
+ type CreateShoppingItemError = {
2
+ productId?: string;
3
+ amountToBuy?: string;
4
+ }
5
+
6
+ type EditShoppingItemError = {
7
+ productId?: string;
8
+ amountToBuy?: string;
9
+ }
10
+
11
+ export type {
12
+ CreateShoppingItemError,
13
+ EditShoppingItemError
14
+ }