Files
klz-cables.com/.pnpm-store/v10/files/f5/8b50f1bc0b035c4b4965d6ee93fd5b9ca211b8d9e0864f29128e6521729d6e57d110c3ed91d19d256c6e520c29a96f9b4f658c52b19ba2e35259db36878e2a
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

58 lines
2.5 KiB
Plaintext

import { withScope, httpRequestToRequestData, captureException } from '@sentry/core';
import { waitUntil, flushSafelyWithTimeout } from '../utils/responseEnd.js';
/**
* Capture the exception passed by nextjs to the `_error` page, adding context data as appropriate.
*
* This will not capture the exception if the status code is < 500 or if the pathname is not provided and will thus not return an event ID.
*
* @param contextOrProps The data passed to either `getInitialProps` or `render` by nextjs
* @returns The Sentry event ID, or `undefined` if no event was captured
*/
async function captureUnderscoreErrorException(contextOrProps) {
const { req, res, err } = contextOrProps;
// 404s (and other 400-y friends) can trigger `_error`, but we don't want to send them to Sentry
const statusCode = res?.statusCode || contextOrProps.statusCode;
if (statusCode && statusCode < 500) {
return;
}
// In previous versions of the suggested `_error.js` page in which this function is meant to be used, there was a
// workaround for https://github.com/vercel/next.js/issues/8592 which involved an extra call to this function, in the
// custom error component's `render` method, just in case it hadn't been called by `getInitialProps`. Now that that
// issue has been fixed, the second call is unnecessary, but since it lives in user code rather than our code, users
// have to be the ones to get rid of it, and guaraneteedly, not all of them will. So, rather than capture the error
// twice, we just bail if we sense we're in that now-extraneous second call. (We can tell which function we're in
// because Nextjs passes `pathname` to `getInitialProps` but not to `render`.)
if (!contextOrProps.pathname) {
return;
}
const eventId = withScope(scope => {
if (req) {
const normalizedRequest = httpRequestToRequestData(req);
scope.setSDKProcessingMetadata({ normalizedRequest });
}
// If third-party libraries (or users themselves) throw something falsy, we want to capture it as a message (which
// is what passing a string to `captureException` will wind up doing)
return captureException(err || `_error.js called with falsy error (${err})`, {
mechanism: {
type: 'auto.function.nextjs.underscore_error',
handled: false,
data: {
function: '_error.getInitialProps',
},
},
});
});
waitUntil(flushSafelyWithTimeout());
return eventId;
}
export { captureUnderscoreErrorException };
//# sourceMappingURL=_error.js.map