MCPcopy
hub / github.com/ampproject/amphtml / onError

Function onError

src/error-reporting.js:321–364  ·  view source on GitHub ↗

* Signature designed, so it can work with window.onerror * @param {string|undefined} message * @param {string|undefined} filename * @param {string|undefined} line * @param {string|undefined} col * @param {*|undefined} error * @this {!Window|undefined}

(message, filename, line, col, error)

Source from the content-addressed store, hash-verified

319 * @this {!Window|undefined}
320 */
321function onError(message, filename, line, col, error) {
322 // Make an attempt to unhide the body but don't if the error is actually expected.
323 // eslint-disable-next-line local/no-invalid-this
324 if (this && this.document && (!error || !error.expected)) {
325 // eslint-disable-next-line local/no-invalid-this
326 makeBodyVisibleRecovery(this.document);
327 }
328 if (getMode().localDev || getMode().development || getMode().test) {
329 return;
330 }
331 let hasNonAmpJs = false;
332 try {
333 hasNonAmpJs = detectNonAmpJs(self);
334 } catch (ignore) {
335 // Ignore errors during error report generation.
336 }
337 if (hasNonAmpJs && Math.random() < NON_AMP_JS_ERROR_THRESHOLD) {
338 return;
339 }
340 const data = getErrorReportData(
341 message,
342 filename,
343 line,
344 col,
345 error,
346 hasNonAmpJs
347 );
348 if (data) {
349 reportingBackoff(() => {
350 try {
351 return reportErrorToServerOrViewer(
352 // eslint-disable-next-line local/no-invalid-this
353 this,
354 /** @type {!JsonObject} */
355 (data)
356 ).catch(() => {
357 // catch async errors to avoid recursive errors.
358 });
359 } catch (e) {
360 // catch async errors to avoid recursive errors.
361 }
362 });
363 }
364}
365
366/**
367 * Determines the error reporting endpoint which should be used.

Callers 5

BentoAutocompleteFunction · 0.85
AutocompleteItemFunction · 0.85
useQueryFunction · 0.85
useDatePickerInputFunction · 0.85
BentoDatePickerWithRefFunction · 0.85

Calls 7

makeBodyVisibleRecoveryFunction · 0.90
getModeFunction · 0.90
detectNonAmpJsFunction · 0.85
getErrorReportDataFunction · 0.85
reportingBackoffFunction · 0.85
catchMethod · 0.80

Tested by

no test coverage detected