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

Function reportErrorToServerOrViewer

src/error-reporting.js:383–399  ·  view source on GitHub ↗
(win, data)

Source from the content-addressed store, hash-verified

381 * @return {Promise<undefined>}
382 */
383export function reportErrorToServerOrViewer(win, data) {
384 // Report the error to viewer if it has the capability. The data passed
385 // to the viewer is exactly the same as the data passed to the server
386 // below.
387
388 if (data['pt'] && Math.random() < THROTTLE_STABLE_THRESHOLD) {
389 return Promise.resolve();
390 }
391
392 return maybeReportErrorToViewer(win, data).then((reportedErrorToViewer) => {
393 if (!reportedErrorToViewer) {
394 const xhr = new XMLHttpRequest();
395 xhr.open('POST', chooseReportingUrl_(), true);
396 xhr.send(JSON.stringify(data));
397 }
398 });
399}
400
401/**
402 * Passes the given error data to the viewer if the following criteria is met:

Callers 2

onErrorFunction · 0.85

Calls 7

maybeReportErrorToViewerFunction · 0.85
chooseReportingUrl_Function · 0.85
resolveMethod · 0.80
stringifyMethod · 0.80
thenMethod · 0.45
openMethod · 0.45
sendMethod · 0.45

Tested by

no test coverage detected