@merchi/cart 1.4.35 → 1.4.37
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/esm/CartProvider.js +4 -1
- package/esm/utilities/invoiceReporting.test.js +7 -2
- package/esm/utilities/reportFailure.js +38 -8
- package/esm/utilities/reportFailure.test.js +20 -1
- package/lib/CartProvider.js +3 -0
- package/lib/utilities/reportFailure.d.ts +8 -5
- package/lib/utilities/reportFailure.js +38 -8
- package/package.json +6 -6
- package/src/CartProvider.tsx +4 -1
- package/src/utilities/invoiceReporting.test.ts +2 -2
- package/src/utilities/reportFailure.test.ts +7 -0
- package/src/utilities/reportFailure.ts +27 -8
package/esm/CartProvider.js
CHANGED
|
@@ -33,7 +33,7 @@ import { makeProduct } from './utilities/product';
|
|
|
33
33
|
import { getSavedCheckoutCustomer, saveCheckoutAddress } from './utilities/local_storage';
|
|
34
34
|
import { makeUser } from './utilities/user';
|
|
35
35
|
import { persistTestCheckoutFlag, readTestCheckoutFlag } from './utilities/test_checkout';
|
|
36
|
-
import { reportAddCartItemFailure } from './utilities/reportFailure';
|
|
36
|
+
import { reportAddCartItemFailure, reportCartFailure, CART_FAILURE_SOURCES } from './utilities/reportFailure';
|
|
37
37
|
import { appendJobSourceToFormData, captureAndReadJobSource, cartNeedsSourceUpdate, jobSourceFieldsForApi } from './utilities/job_source';
|
|
38
38
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
39
39
|
var CartContext = /*#__PURE__*/createContext({
|
|
@@ -542,6 +542,7 @@ var CartProvider = function CartProvider(_ref) {
|
|
|
542
542
|
case 5:
|
|
543
543
|
_context2.p = 5;
|
|
544
544
|
_t3 = _context2.v;
|
|
545
|
+
reportCartFailure(_t3, CART_FAILURE_SOURCES.create);
|
|
545
546
|
alertError(_t3.errorMessage || _t3.message || 'Unable to fetch cart.');
|
|
546
547
|
case 6:
|
|
547
548
|
_context2.p = 6;
|
|
@@ -775,6 +776,7 @@ var CartProvider = function CartProvider(_ref) {
|
|
|
775
776
|
case 5:
|
|
776
777
|
_context7.p = 5;
|
|
777
778
|
_t5 = _context7.v;
|
|
779
|
+
reportCartFailure(_t5, CART_FAILURE_SOURCES.update);
|
|
778
780
|
alertError(_t5.errorMessage || _t5.message || 'Unable to set address');
|
|
779
781
|
case 6:
|
|
780
782
|
_context7.p = 6;
|
|
@@ -815,6 +817,7 @@ var CartProvider = function CartProvider(_ref) {
|
|
|
815
817
|
case 3:
|
|
816
818
|
_context8.p = 3;
|
|
817
819
|
_t6 = _context8.v;
|
|
820
|
+
reportCartFailure(_t6, CART_FAILURE_SOURCES.shipping);
|
|
818
821
|
alertError(_t6.errorMessage || _t6.message || 'Unable to fetch shipment options');
|
|
819
822
|
case 4:
|
|
820
823
|
_context8.p = 4;
|
|
@@ -159,7 +159,7 @@ describe('generatePublicInvoicePdf error reporting', function () {
|
|
|
159
159
|
}
|
|
160
160
|
}, _callee8);
|
|
161
161
|
})));
|
|
162
|
-
it('
|
|
162
|
+
it('retains unresolved invoice failures even with client error codes', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee0() {
|
|
163
163
|
var error;
|
|
164
164
|
return _regenerator().w(function (_context0) {
|
|
165
165
|
while (1) switch (_context0.n) {
|
|
@@ -184,7 +184,12 @@ describe('generatePublicInvoicePdf error reporting', function () {
|
|
|
184
184
|
}
|
|
185
185
|
})).rejects.toBe(error);
|
|
186
186
|
case 1:
|
|
187
|
-
expect(events).
|
|
187
|
+
expect(events[0]).toMatchObject({
|
|
188
|
+
operation: {
|
|
189
|
+
name: 'cart.invoice_pdf',
|
|
190
|
+
outcome: 'failed'
|
|
191
|
+
}
|
|
192
|
+
});
|
|
188
193
|
case 2:
|
|
189
194
|
return _context0.a(2);
|
|
190
195
|
}
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
6
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
1
7
|
import { captureUnexpected } from '@merchi/error-catch';
|
|
2
8
|
|
|
3
9
|
/**
|
|
@@ -6,33 +12,57 @@ import { captureUnexpected } from '@merchi/error-catch';
|
|
|
6
12
|
* `CaptureContext.source` only accepts the error-catch enum (`manual`,
|
|
7
13
|
* `window_error`, `unhandled_rejection`, `react_error_boundary`). Any other
|
|
8
14
|
* string is coerced to `manual` and dropped, so the call site is sent as
|
|
9
|
-
* `digest
|
|
15
|
+
* the legacy `digest` as well as bounded operation context.
|
|
10
16
|
*/
|
|
11
17
|
export var CART_FAILURE_SOURCES = {
|
|
12
18
|
addItem: 'cart.addItem',
|
|
13
|
-
invoicePdf: 'cart.invoicePdf'
|
|
19
|
+
invoicePdf: 'cart.invoicePdf',
|
|
20
|
+
create: 'cart.create',
|
|
21
|
+
update: 'cart.update',
|
|
22
|
+
shipping: 'cart.shipping'
|
|
23
|
+
};
|
|
24
|
+
var OPERATIONS = {
|
|
25
|
+
'cart.addItem': 'cart.add_item',
|
|
26
|
+
'cart.invoicePdf': 'cart.invoice_pdf',
|
|
27
|
+
'cart.create': 'cart.create',
|
|
28
|
+
'cart.update': 'cart.update',
|
|
29
|
+
'cart.shipping': 'cart.shipping'
|
|
14
30
|
};
|
|
15
31
|
/**
|
|
16
32
|
* Report an unexpected cart failure.
|
|
17
33
|
*
|
|
18
|
-
* `captureUnexpected` normalises non-Error rejections
|
|
19
|
-
*
|
|
34
|
+
* `captureUnexpected` normalises non-Error rejections. Failed operations remain
|
|
35
|
+
* reportable even for client status codes. The call is a no-op until
|
|
20
36
|
* the host configures `@merchi/error-catch`, and a failure inside reporting
|
|
21
37
|
* never replaces the original error.
|
|
22
38
|
*/
|
|
23
39
|
export function reportCartFailure(error, source) {
|
|
40
|
+
var handledValidation = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
24
41
|
try {
|
|
25
42
|
captureUnexpected(error, {
|
|
26
43
|
source: 'manual',
|
|
27
|
-
digest: source
|
|
44
|
+
digest: source,
|
|
45
|
+
operation: _objectSpread({
|
|
46
|
+
name: OPERATIONS[source],
|
|
47
|
+
outcome: handledValidation ? 'handled' : 'failed'
|
|
48
|
+
}, handledValidation ? {
|
|
49
|
+
reason: 'validation'
|
|
50
|
+
} : {})
|
|
28
51
|
});
|
|
29
52
|
} catch (_unused) {
|
|
30
53
|
// Reporting must not replace the original failure.
|
|
31
54
|
}
|
|
32
55
|
}
|
|
33
56
|
|
|
34
|
-
/**
|
|
57
|
+
/** Invoke the UI callback, then report using its confirmed handling outcome. */
|
|
35
58
|
export function reportAddCartItemFailure(error, onError) {
|
|
36
|
-
|
|
37
|
-
|
|
59
|
+
var handled = false;
|
|
60
|
+
try {
|
|
61
|
+
onError(error);
|
|
62
|
+
handled = true;
|
|
63
|
+
} finally {
|
|
64
|
+
// A displayed error is only suppressed if the shared policy also verifies
|
|
65
|
+
// a known input code/status. A callback that crashes cannot mark it handled.
|
|
66
|
+
reportCartFailure(error, CART_FAILURE_SOURCES.addItem, handled);
|
|
67
|
+
}
|
|
38
68
|
}
|
|
@@ -33,7 +33,12 @@ describe('reportAddCartItemFailure', function () {
|
|
|
33
33
|
digest: 'cart.addItem',
|
|
34
34
|
errorType: 'TypeError',
|
|
35
35
|
message: 'cart item create failed',
|
|
36
|
-
source: 'manual'
|
|
36
|
+
source: 'manual',
|
|
37
|
+
operation: {
|
|
38
|
+
name: 'cart.add_item',
|
|
39
|
+
outcome: 'handled',
|
|
40
|
+
reason: 'validation'
|
|
41
|
+
}
|
|
37
42
|
});
|
|
38
43
|
});
|
|
39
44
|
it('normalises a non-Error rejection and forwards the original value', function () {
|
|
@@ -64,6 +69,20 @@ describe('reportAddCartItemFailure', function () {
|
|
|
64
69
|
message: 'cart service down'
|
|
65
70
|
});
|
|
66
71
|
});
|
|
72
|
+
it('retains a client-shaped failure when the UI callback itself fails', function () {
|
|
73
|
+
var error = apiError(422, 'input error');
|
|
74
|
+
expect(function () {
|
|
75
|
+
return reportAddCartItemFailure(error, function () {
|
|
76
|
+
throw new Error('UI broke');
|
|
77
|
+
});
|
|
78
|
+
}).toThrow('UI broke');
|
|
79
|
+
expect(events[0]).toMatchObject({
|
|
80
|
+
operation: {
|
|
81
|
+
name: 'cart.add_item',
|
|
82
|
+
outcome: 'failed'
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
});
|
|
67
86
|
});
|
|
68
87
|
describe('reportCartFailure before error-catch is configured', function () {
|
|
69
88
|
it('does not throw and does not create a reporter', function () {
|
package/lib/CartProvider.js
CHANGED
|
@@ -548,6 +548,7 @@ var CartProvider = function CartProvider(_ref) {
|
|
|
548
548
|
case 5:
|
|
549
549
|
_context2.p = 5;
|
|
550
550
|
_t3 = _context2.v;
|
|
551
|
+
(0, _reportFailure.reportCartFailure)(_t3, _reportFailure.CART_FAILURE_SOURCES.create);
|
|
551
552
|
alertError(_t3.errorMessage || _t3.message || 'Unable to fetch cart.');
|
|
552
553
|
case 6:
|
|
553
554
|
_context2.p = 6;
|
|
@@ -781,6 +782,7 @@ var CartProvider = function CartProvider(_ref) {
|
|
|
781
782
|
case 5:
|
|
782
783
|
_context7.p = 5;
|
|
783
784
|
_t5 = _context7.v;
|
|
785
|
+
(0, _reportFailure.reportCartFailure)(_t5, _reportFailure.CART_FAILURE_SOURCES.update);
|
|
784
786
|
alertError(_t5.errorMessage || _t5.message || 'Unable to set address');
|
|
785
787
|
case 6:
|
|
786
788
|
_context7.p = 6;
|
|
@@ -821,6 +823,7 @@ var CartProvider = function CartProvider(_ref) {
|
|
|
821
823
|
case 3:
|
|
822
824
|
_context8.p = 3;
|
|
823
825
|
_t6 = _context8.v;
|
|
826
|
+
(0, _reportFailure.reportCartFailure)(_t6, _reportFailure.CART_FAILURE_SOURCES.shipping);
|
|
824
827
|
alertError(_t6.errorMessage || _t6.message || 'Unable to fetch shipment options');
|
|
825
828
|
case 4:
|
|
826
829
|
_context8.p = 4;
|
|
@@ -4,21 +4,24 @@
|
|
|
4
4
|
* `CaptureContext.source` only accepts the error-catch enum (`manual`,
|
|
5
5
|
* `window_error`, `unhandled_rejection`, `react_error_boundary`). Any other
|
|
6
6
|
* string is coerced to `manual` and dropped, so the call site is sent as
|
|
7
|
-
* `digest
|
|
7
|
+
* the legacy `digest` as well as bounded operation context.
|
|
8
8
|
*/
|
|
9
9
|
export declare const CART_FAILURE_SOURCES: {
|
|
10
10
|
readonly addItem: "cart.addItem";
|
|
11
11
|
readonly invoicePdf: "cart.invoicePdf";
|
|
12
|
+
readonly create: "cart.create";
|
|
13
|
+
readonly update: "cart.update";
|
|
14
|
+
readonly shipping: "cart.shipping";
|
|
12
15
|
};
|
|
13
16
|
export type CartFailureSource = (typeof CART_FAILURE_SOURCES)[keyof typeof CART_FAILURE_SOURCES];
|
|
14
17
|
/**
|
|
15
18
|
* Report an unexpected cart failure.
|
|
16
19
|
*
|
|
17
|
-
* `captureUnexpected` normalises non-Error rejections
|
|
18
|
-
*
|
|
20
|
+
* `captureUnexpected` normalises non-Error rejections. Failed operations remain
|
|
21
|
+
* reportable even for client status codes. The call is a no-op until
|
|
19
22
|
* the host configures `@merchi/error-catch`, and a failure inside reporting
|
|
20
23
|
* never replaces the original error.
|
|
21
24
|
*/
|
|
22
|
-
export declare function reportCartFailure(error: unknown, source: CartFailureSource): void;
|
|
23
|
-
/**
|
|
25
|
+
export declare function reportCartFailure(error: unknown, source: CartFailureSource, handledValidation?: boolean): void;
|
|
26
|
+
/** Invoke the UI callback, then report using its confirmed handling outcome. */
|
|
24
27
|
export declare function reportAddCartItemFailure(error: unknown, onError: (error: any) => void): void;
|
|
@@ -7,39 +7,69 @@ exports.CART_FAILURE_SOURCES = void 0;
|
|
|
7
7
|
exports.reportAddCartItemFailure = reportAddCartItemFailure;
|
|
8
8
|
exports.reportCartFailure = reportCartFailure;
|
|
9
9
|
var _errorCatch = require("@merchi/error-catch");
|
|
10
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
11
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
12
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
13
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
14
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
15
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
10
16
|
/**
|
|
11
17
|
* Call-site tags recorded on the error-catch event.
|
|
12
18
|
*
|
|
13
19
|
* `CaptureContext.source` only accepts the error-catch enum (`manual`,
|
|
14
20
|
* `window_error`, `unhandled_rejection`, `react_error_boundary`). Any other
|
|
15
21
|
* string is coerced to `manual` and dropped, so the call site is sent as
|
|
16
|
-
* `digest
|
|
22
|
+
* the legacy `digest` as well as bounded operation context.
|
|
17
23
|
*/
|
|
18
24
|
var CART_FAILURE_SOURCES = exports.CART_FAILURE_SOURCES = {
|
|
19
25
|
addItem: 'cart.addItem',
|
|
20
|
-
invoicePdf: 'cart.invoicePdf'
|
|
26
|
+
invoicePdf: 'cart.invoicePdf',
|
|
27
|
+
create: 'cart.create',
|
|
28
|
+
update: 'cart.update',
|
|
29
|
+
shipping: 'cart.shipping'
|
|
30
|
+
};
|
|
31
|
+
var OPERATIONS = {
|
|
32
|
+
'cart.addItem': 'cart.add_item',
|
|
33
|
+
'cart.invoicePdf': 'cart.invoice_pdf',
|
|
34
|
+
'cart.create': 'cart.create',
|
|
35
|
+
'cart.update': 'cart.update',
|
|
36
|
+
'cart.shipping': 'cart.shipping'
|
|
21
37
|
};
|
|
22
38
|
/**
|
|
23
39
|
* Report an unexpected cart failure.
|
|
24
40
|
*
|
|
25
|
-
* `captureUnexpected` normalises non-Error rejections
|
|
26
|
-
*
|
|
41
|
+
* `captureUnexpected` normalises non-Error rejections. Failed operations remain
|
|
42
|
+
* reportable even for client status codes. The call is a no-op until
|
|
27
43
|
* the host configures `@merchi/error-catch`, and a failure inside reporting
|
|
28
44
|
* never replaces the original error.
|
|
29
45
|
*/
|
|
30
46
|
function reportCartFailure(error, source) {
|
|
47
|
+
var handledValidation = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
31
48
|
try {
|
|
32
49
|
(0, _errorCatch.captureUnexpected)(error, {
|
|
33
50
|
source: 'manual',
|
|
34
|
-
digest: source
|
|
51
|
+
digest: source,
|
|
52
|
+
operation: _objectSpread({
|
|
53
|
+
name: OPERATIONS[source],
|
|
54
|
+
outcome: handledValidation ? 'handled' : 'failed'
|
|
55
|
+
}, handledValidation ? {
|
|
56
|
+
reason: 'validation'
|
|
57
|
+
} : {})
|
|
35
58
|
});
|
|
36
59
|
} catch (_unused) {
|
|
37
60
|
// Reporting must not replace the original failure.
|
|
38
61
|
}
|
|
39
62
|
}
|
|
40
63
|
|
|
41
|
-
/**
|
|
64
|
+
/** Invoke the UI callback, then report using its confirmed handling outcome. */
|
|
42
65
|
function reportAddCartItemFailure(error, onError) {
|
|
43
|
-
|
|
44
|
-
|
|
66
|
+
var handled = false;
|
|
67
|
+
try {
|
|
68
|
+
onError(error);
|
|
69
|
+
handled = true;
|
|
70
|
+
} finally {
|
|
71
|
+
// A displayed error is only suppressed if the shared policy also verifies
|
|
72
|
+
// a known input code/status. A callback that crashes cannot mark it handled.
|
|
73
|
+
reportCartFailure(error, CART_FAILURE_SOURCES.addItem, handled);
|
|
74
|
+
}
|
|
45
75
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@merchi/cart",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.37",
|
|
4
4
|
"description": "Merchi's cart",
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -93,11 +93,11 @@
|
|
|
93
93
|
"@fortawesome/fontawesome-svg-core": "6.4.2",
|
|
94
94
|
"@fortawesome/free-solid-svg-icons": "6.4.2",
|
|
95
95
|
"@fortawesome/react-fontawesome": "^0.2.0",
|
|
96
|
-
"@merchi/error-catch": "^0.1.
|
|
97
|
-
"@merchi/invoice": "^1.3.
|
|
98
|
-
"@merchi/product-form": "^1.19.
|
|
99
|
-
"@merchi/product-form-sdk": "^1.0.
|
|
100
|
-
"@merchi/sdk": "^1.42.
|
|
96
|
+
"@merchi/error-catch": "^0.1.3",
|
|
97
|
+
"@merchi/invoice": "^1.3.7",
|
|
98
|
+
"@merchi/product-form": "^1.19.40",
|
|
99
|
+
"@merchi/product-form-sdk": "^1.0.28",
|
|
100
|
+
"@merchi/sdk": "^1.42.17",
|
|
101
101
|
"@stripe/react-stripe-js": "^2.3.0",
|
|
102
102
|
"@stripe/stripe-js": "^2.1.6",
|
|
103
103
|
"browser-or-node": "^3.0.0-pre.0",
|
package/src/CartProvider.tsx
CHANGED
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
} from './utilities/local_storage';
|
|
22
22
|
import { makeUser } from './utilities/user';
|
|
23
23
|
import { persistTestCheckoutFlag, readTestCheckoutFlag } from './utilities/test_checkout';
|
|
24
|
-
import { reportAddCartItemFailure } from './utilities/reportFailure';
|
|
24
|
+
import { reportAddCartItemFailure, reportCartFailure, CART_FAILURE_SOURCES } from './utilities/reportFailure';
|
|
25
25
|
import {
|
|
26
26
|
appendJobSourceToFormData,
|
|
27
27
|
captureAndReadJobSource,
|
|
@@ -649,6 +649,7 @@ const CartProvider = ({
|
|
|
649
649
|
setCart({...cartJson});
|
|
650
650
|
if (callback) callback();
|
|
651
651
|
} catch (e: any) {
|
|
652
|
+
reportCartFailure(e, CART_FAILURE_SOURCES.create);
|
|
652
653
|
alertError(e.errorMessage || e.message || 'Unable to fetch cart.');
|
|
653
654
|
} finally {
|
|
654
655
|
setFetchingCart(false);
|
|
@@ -754,6 +755,7 @@ const CartProvider = ({
|
|
|
754
755
|
shipmentGroups: cartWithShipmentGroups.shipmentGroups || []
|
|
755
756
|
});
|
|
756
757
|
} catch (e: any) {
|
|
758
|
+
reportCartFailure(e, CART_FAILURE_SOURCES.update);
|
|
757
759
|
alertError(e.errorMessage || e.message || 'Unable to set address');
|
|
758
760
|
} finally {
|
|
759
761
|
setFetchingShipmentGroups(false);
|
|
@@ -774,6 +776,7 @@ const CartProvider = ({
|
|
|
774
776
|
shipmentGroups: cartWithGroups.shipmentGroups || []
|
|
775
777
|
});
|
|
776
778
|
} catch (e: any) {
|
|
779
|
+
reportCartFailure(e, CART_FAILURE_SOURCES.shipping);
|
|
777
780
|
alertError(e.errorMessage || e.message || 'Unable to fetch shipment options');
|
|
778
781
|
} finally {
|
|
779
782
|
setFetchingShipmentGroups(false);
|
|
@@ -97,7 +97,7 @@ describe('generatePublicInvoicePdf error reporting', () => {
|
|
|
97
97
|
expect(JSON.stringify(events[0])).not.toContain('person@example.com');
|
|
98
98
|
});
|
|
99
99
|
|
|
100
|
-
it('
|
|
100
|
+
it('retains unresolved invoice failures even with client error codes', async () => {
|
|
101
101
|
const error = apiError(409, 'invoice token rejected');
|
|
102
102
|
global.fetch = jest.fn(async () => {
|
|
103
103
|
throw error;
|
|
@@ -109,6 +109,6 @@ describe('generatePublicInvoicePdf error reporting', () => {
|
|
|
109
109
|
domain: { emailDomain: 'shop.example' },
|
|
110
110
|
})).rejects.toBe(error);
|
|
111
111
|
|
|
112
|
-
expect(events).
|
|
112
|
+
expect(events[0]).toMatchObject({ operation: { name: 'cart.invoice_pdf', outcome: 'failed' } });
|
|
113
113
|
});
|
|
114
114
|
});
|
|
@@ -43,6 +43,7 @@ describe('reportAddCartItemFailure', () => {
|
|
|
43
43
|
errorType: 'TypeError',
|
|
44
44
|
message: 'cart item create failed',
|
|
45
45
|
source: 'manual',
|
|
46
|
+
operation: { name: 'cart.add_item', outcome: 'handled', reason: 'validation' },
|
|
46
47
|
});
|
|
47
48
|
});
|
|
48
49
|
|
|
@@ -82,6 +83,12 @@ describe('reportAddCartItemFailure', () => {
|
|
|
82
83
|
message: 'cart service down',
|
|
83
84
|
});
|
|
84
85
|
});
|
|
86
|
+
|
|
87
|
+
it('retains a client-shaped failure when the UI callback itself fails', () => {
|
|
88
|
+
const error = apiError(422, 'input error');
|
|
89
|
+
expect(() => reportAddCartItemFailure(error, () => { throw new Error('UI broke'); })).toThrow('UI broke');
|
|
90
|
+
expect(events[0]).toMatchObject({ operation: { name: 'cart.add_item', outcome: 'failed' } });
|
|
91
|
+
});
|
|
85
92
|
});
|
|
86
93
|
|
|
87
94
|
describe('reportCartFailure before error-catch is configured', () => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { captureUnexpected } from '@merchi/error-catch';
|
|
1
|
+
import { captureUnexpected, type FrontendErrorOperation } from '@merchi/error-catch';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Call-site tags recorded on the error-catch event.
|
|
@@ -6,12 +6,19 @@ import { captureUnexpected } from '@merchi/error-catch';
|
|
|
6
6
|
* `CaptureContext.source` only accepts the error-catch enum (`manual`,
|
|
7
7
|
* `window_error`, `unhandled_rejection`, `react_error_boundary`). Any other
|
|
8
8
|
* string is coerced to `manual` and dropped, so the call site is sent as
|
|
9
|
-
* `digest
|
|
9
|
+
* the legacy `digest` as well as bounded operation context.
|
|
10
10
|
*/
|
|
11
11
|
export const CART_FAILURE_SOURCES = {
|
|
12
12
|
addItem: 'cart.addItem',
|
|
13
13
|
invoicePdf: 'cart.invoicePdf',
|
|
14
|
+
create: 'cart.create',
|
|
15
|
+
update: 'cart.update',
|
|
16
|
+
shipping: 'cart.shipping',
|
|
14
17
|
} as const;
|
|
18
|
+
const OPERATIONS: Record<CartFailureSource, FrontendErrorOperation> = {
|
|
19
|
+
'cart.addItem': 'cart.add_item', 'cart.invoicePdf': 'cart.invoice_pdf',
|
|
20
|
+
'cart.create': 'cart.create', 'cart.update': 'cart.update', 'cart.shipping': 'cart.shipping',
|
|
21
|
+
};
|
|
15
22
|
|
|
16
23
|
export type CartFailureSource =
|
|
17
24
|
(typeof CART_FAILURE_SOURCES)[keyof typeof CART_FAILURE_SOURCES];
|
|
@@ -19,27 +26,39 @@ export type CartFailureSource =
|
|
|
19
26
|
/**
|
|
20
27
|
* Report an unexpected cart failure.
|
|
21
28
|
*
|
|
22
|
-
* `captureUnexpected` normalises non-Error rejections
|
|
23
|
-
*
|
|
29
|
+
* `captureUnexpected` normalises non-Error rejections. Failed operations remain
|
|
30
|
+
* reportable even for client status codes. The call is a no-op until
|
|
24
31
|
* the host configures `@merchi/error-catch`, and a failure inside reporting
|
|
25
32
|
* never replaces the original error.
|
|
26
33
|
*/
|
|
27
|
-
export function reportCartFailure(error: unknown, source: CartFailureSource): void {
|
|
34
|
+
export function reportCartFailure(error: unknown, source: CartFailureSource, handledValidation = false): void {
|
|
28
35
|
try {
|
|
29
36
|
captureUnexpected(error, {
|
|
30
37
|
source: 'manual',
|
|
31
38
|
digest: source,
|
|
39
|
+
operation: {
|
|
40
|
+
name: OPERATIONS[source],
|
|
41
|
+
outcome: handledValidation ? 'handled' : 'failed',
|
|
42
|
+
...(handledValidation ? { reason: 'validation' as const } : {}),
|
|
43
|
+
},
|
|
32
44
|
});
|
|
33
45
|
} catch {
|
|
34
46
|
// Reporting must not replace the original failure.
|
|
35
47
|
}
|
|
36
48
|
}
|
|
37
49
|
|
|
38
|
-
/**
|
|
50
|
+
/** Invoke the UI callback, then report using its confirmed handling outcome. */
|
|
39
51
|
export function reportAddCartItemFailure(
|
|
40
52
|
error: unknown,
|
|
41
53
|
onError: (error: any) => void,
|
|
42
54
|
): void {
|
|
43
|
-
|
|
44
|
-
|
|
55
|
+
let handled = false;
|
|
56
|
+
try {
|
|
57
|
+
onError(error);
|
|
58
|
+
handled = true;
|
|
59
|
+
} finally {
|
|
60
|
+
// A displayed error is only suppressed if the shared policy also verifies
|
|
61
|
+
// a known input code/status. A callback that crashes cannot mark it handled.
|
|
62
|
+
reportCartFailure(error, CART_FAILURE_SOURCES.addItem, handled);
|
|
63
|
+
}
|
|
45
64
|
}
|