| @@ -1,11 +1,40 @@ | ||
| 1 | 1 | import { AI_HOST } from '@constants'; |
| 2 | 2 | import { reqDataBasics } from '@shared/lib/data'; |
| 3 | 3 | |
| 4 | -// ctx, can be any extra data you want to pass to the digest for better insights, e.g. { function: 'handleSiteLogo' } | |
| 4 | +// Retried steps re-report the same failure; one site sent 89k rows before this. | |
| 5 | +const sent = new Set(); | |
| 6 | + | |
| 7 | +const describeError = (e) => { | |
| 8 | + if (!e) return { message: 'Unknown error', name: 'Error', stack: '' }; | |
| 9 | + if (e instanceof Response) { | |
| 10 | + return { | |
| 11 | + message: `HTTP ${e.status}: ${e.statusText}`, | |
| 12 | + name: 'FetchError', | |
| 13 | + stack: '', | |
| 14 | + }; | |
| 15 | + } | |
| 16 | + return { | |
| 17 | + message: | |
| 18 | + e?.response?.statusText || | |
| 19 | + e?.response?.message || | |
| 20 | + e?.statusText || | |
| 21 | + e?.message || | |
| 22 | + (typeof e === 'string' ? e : 'Unknown error'), | |
| 23 | + name: e?.name || 'Error', | |
| 24 | + // WordPress localizes the message; the code is what groups it. | |
| 25 | + code: e?.code, | |
| 26 | + }; | |
| 27 | +}; | |
| 28 | + | |
| 5 | 29 | export const digest = ({ type = 'error', error, details = {} } = {}) => { |
| 6 | 30 | if (Boolean(reqDataBasics?.devbuild) === true) return; |
| 7 | 31 | |
| 32 | + const errorData = describeError(error); | |
| 33 | + const key = JSON.stringify([type, details, errorData]); | |
| 34 | + if (sent.has(key)) return; | |
| 35 | + sent.add(key); | |
| 36 | + | |
| 8 | 37 | const extra = { |
| 9 | 38 | userAgent: window?.navigator?.userAgent, |
| 10 | 39 | vendor: window?.navigator?.vendor || 'unknown', |
| 11 | 40 | platform: |
| @@ -19,27 +48,8 @@ | ||
| 19 | 48 | screenWidth: window.screen.width, |
| 20 | 49 | orientation: window.screen.orientation?.type, |
| 21 | 50 | touchSupport: 'ontouchstart' in window || navigator.maxTouchPoints > 0, |
| 22 | 51 | }; |
| 23 | - | |
| 24 | - const errorData = ((e) => { | |
| 25 | - if (!e) return { message: 'Unknown error', name: 'Error', stack: '' }; | |
| 26 | - if (e instanceof Response) | |
| 27 | - return { | |
| 28 | - message: `HTTP ${e.status}: ${e.statusText}`, | |
| 29 | - name: 'FetchError', | |
| 30 | - stack: '', | |
| 31 | - }; | |
| 32 | - return { | |
| 33 | - message: | |
| 34 | - e?.response?.statusText || | |
| 35 | - e?.response?.message || | |
| 36 | - e?.statusText || | |
| 37 | - e?.message || | |
| 38 | - (typeof e === 'string' ? e : 'Unknown error'), | |
| 39 | - name: e?.name || 'Error', | |
| 40 | - }; | |
| 41 | - })(error); | |
| 42 | 52 | |
| 43 | 53 | const payload = JSON.stringify({ |
| 44 | 54 | ...reqDataBasics, |
| 45 | 55 | siteProfile: { |