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,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
|
|