123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- Object.defineProperty(exports, '__esModule', { value: true });
- const is = require('./is.js');
- const string = require('./string.js');
- /**
- * Creates exceptions inside `event.exception.values` for errors that are nested on properties based on the `key` parameter.
- */
- function applyAggregateErrorsToEvent(
- exceptionFromErrorImplementation,
- parser,
- maxValueLimit = 250,
- key,
- limit,
- event,
- hint,
- ) {
- if (!event.exception || !event.exception.values || !hint || !is.isInstanceOf(hint.originalException, Error)) {
- return;
- }
- // Generally speaking the last item in `event.exception.values` is the exception originating from the original Error
- const originalException =
- event.exception.values.length > 0 ? event.exception.values[event.exception.values.length - 1] : undefined;
- // We only create exception grouping if there is an exception in the event.
- if (originalException) {
- event.exception.values = truncateAggregateExceptions(
- aggregateExceptionsFromError(
- exceptionFromErrorImplementation,
- parser,
- limit,
- hint.originalException ,
- key,
- event.exception.values,
- originalException,
- 0,
- ),
- maxValueLimit,
- );
- }
- }
- function aggregateExceptionsFromError(
- exceptionFromErrorImplementation,
- parser,
- limit,
- error,
- key,
- prevExceptions,
- exception,
- exceptionId,
- ) {
- if (prevExceptions.length >= limit + 1) {
- return prevExceptions;
- }
- let newExceptions = [...prevExceptions];
- if (is.isInstanceOf(error[key], Error)) {
- applyExceptionGroupFieldsForParentException(exception, exceptionId);
- const newException = exceptionFromErrorImplementation(parser, error[key]);
- const newExceptionId = newExceptions.length;
- applyExceptionGroupFieldsForChildException(newException, key, newExceptionId, exceptionId);
- newExceptions = aggregateExceptionsFromError(
- exceptionFromErrorImplementation,
- parser,
- limit,
- error[key],
- key,
- [newException, ...newExceptions],
- newException,
- newExceptionId,
- );
- }
- // This will create exception grouping for AggregateErrors
- // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AggregateError
- if (Array.isArray(error.errors)) {
- error.errors.forEach((childError, i) => {
- if (is.isInstanceOf(childError, Error)) {
- applyExceptionGroupFieldsForParentException(exception, exceptionId);
- const newException = exceptionFromErrorImplementation(parser, childError);
- const newExceptionId = newExceptions.length;
- applyExceptionGroupFieldsForChildException(newException, `errors[${i}]`, newExceptionId, exceptionId);
- newExceptions = aggregateExceptionsFromError(
- exceptionFromErrorImplementation,
- parser,
- limit,
- childError,
- key,
- [newException, ...newExceptions],
- newException,
- newExceptionId,
- );
- }
- });
- }
- return newExceptions;
- }
- function applyExceptionGroupFieldsForParentException(exception, exceptionId) {
- // Don't know if this default makes sense. The protocol requires us to set these values so we pick *some* default.
- exception.mechanism = exception.mechanism || { type: 'generic', handled: true };
- exception.mechanism = {
- ...exception.mechanism,
- is_exception_group: true,
- exception_id: exceptionId,
- };
- }
- function applyExceptionGroupFieldsForChildException(
- exception,
- source,
- exceptionId,
- parentId,
- ) {
- // Don't know if this default makes sense. The protocol requires us to set these values so we pick *some* default.
- exception.mechanism = exception.mechanism || { type: 'generic', handled: true };
- exception.mechanism = {
- ...exception.mechanism,
- type: 'chained',
- source,
- exception_id: exceptionId,
- parent_id: parentId,
- };
- }
- /**
- * Truncate the message (exception.value) of all exceptions in the event.
- * Because this event processor is ran after `applyClientOptions`,
- * we need to truncate the message of the added exceptions here.
- */
- function truncateAggregateExceptions(exceptions, maxValueLength) {
- return exceptions.map(exception => {
- if (exception.value) {
- exception.value = string.truncate(exception.value, maxValueLength);
- }
- return exception;
- });
- }
- exports.applyAggregateErrorsToEvent = applyAggregateErrorsToEvent;
- //# sourceMappingURL=aggregate-errors.js.map
|