UNPKG

@sentry/nextjs

Version:
65 lines (61 loc) • 2.54 kB
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); const core = require('@sentry/core'); const nextNavigationErrorUtils = require('./nextNavigationErrorUtils.js'); const responseEnd = require('./utils/responseEnd.js'); function wrapGenerationFunctionWithSentry(generationFunction, context) { return new Proxy(generationFunction, { apply: (originalFunction, thisArg, args) => { const isolationScope = core.getIsolationScope(); let headers = void 0; try { headers = context.requestAsyncStorage?.getStore()?.headers; } catch { } const headersDict = headers ? core.winterCGHeadersToDict(headers) : void 0; isolationScope.setSDKProcessingMetadata({ normalizedRequest: { headers: headersDict } }); return core.handleCallbackErrors( () => originalFunction.apply(thisArg, args), (error) => { const span = core.getActiveSpan(); const { componentRoute, componentType, generationFunctionIdentifier } = context; isolationScope.setTransactionName(`${componentType}.${generationFunctionIdentifier} (${componentRoute})`); if (nextNavigationErrorUtils.isNotFoundNavigationError(error)) { span?.setStatus({ code: core.SPAN_STATUS_ERROR, message: "not_found" }); return; } const authInterruptStatusCode = nextNavigationErrorUtils.getAuthInterruptStatusCode(error); if (authInterruptStatusCode) { span?.setStatus(core.getSpanStatusFromHttpCode(authInterruptStatusCode)); return; } if (nextNavigationErrorUtils.isRedirectNavigationError(error)) { span?.setStatus({ code: core.SPAN_STATUS_OK }); return; } if (nextNavigationErrorUtils.isPrerenderControlFlowError(error)) { return; } span?.setStatus({ code: core.SPAN_STATUS_ERROR, message: "internal_error" }); core.captureException(error, { mechanism: { handled: false, type: "auto.function.nextjs.generation_function", data: { function: generationFunctionIdentifier } } }); }, () => { responseEnd.waitUntil(responseEnd.flushSafelyWithTimeout()); } ); } }); } exports.wrapGenerationFunctionWithSentry = wrapGenerationFunctionWithSentry; //# sourceMappingURL=wrapGenerationFunctionWithSentry.js.map