UNPKG

@atlaskit/profilecard

Version:

A React component to display a card with user information.

89 lines (87 loc) 3.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.handleDirectoryGraphQLErrors = exports.handleAGGErrors = exports.getErrorAttributes = void 0; var _errors = require("../util/errors"); var IGNORED_ERROR_REASONS_DIRECTORY = [ // Error categories from pf-directory 'NotPermitted', 'Gone', 'IdentityUserNotFoundError']; var IGNORE_ERROR_TYPES_AGG = ['IdentityUserNotFoundError', 'TEAMS_FORBIDDEN', 'TEAMS_TEAM_DELETED']; var IGNORE_ERROR_CLASSIFICATIONS_AGG = ['Gone']; function isIgnoredError(error) { if (!error) { return false; } if (error instanceof _errors.DirectoryGraphQLError) { return !!error && IGNORED_ERROR_REASONS_DIRECTORY.includes(error.type); } else if (error instanceof _errors.AGGError) { return !!error.errorType && IGNORE_ERROR_TYPES_AGG.includes(error.errorType) || !!error.classification && IGNORE_ERROR_CLASSIFICATIONS_AGG.includes(error.classification); } return false; } var _getErrorAttributes = exports.getErrorAttributes = function getErrorAttributes(error) { if (error instanceof _errors.DirectoryGraphQLErrors) { return { errorMessage: error.message, errorCount: error.errors.length, errorDetails: error.errors.map(_getErrorAttributes), isSLOFailure: !error.errors.every(isIgnoredError), traceId: error.traceId }; } else if (error instanceof _errors.DirectoryGraphQLError) { return { errorMessage: error.message, errorCategory: error.category, errorType: error.type, errorPath: error.path, errorNumber: error.errorNumber, isSLOFailure: !isIgnoredError(error) }; } else if (error instanceof _errors.AGGErrors) { return { errorMessage: error.message, errorCount: error.errors.length, errorDetails: error.errors.map(_getErrorAttributes), isSLOFailure: !error.errors.every(isIgnoredError), traceId: error.traceId }; } else if (error instanceof _errors.AGGError) { return { errorMessage: error.message, errorType: error.errorType, errorStatusCode: error.statusCode, isSLOFailure: !isIgnoredError(error), errorCategory: error.classification }; } else if (error instanceof Error) { // Jira custom profile card client error, they wrap the error & put the underlying error in the cause property if (error.message.startsWith('Unable to fetch user:')) { if (error.hasOwnProperty('cause')) { var causeError = error.cause; if (causeError instanceof _errors.DirectoryGraphQLErrors || causeError instanceof _errors.AGGErrors) { return _getErrorAttributes(causeError); } } return { errorMessage: error.message, isSLOFailure: false }; } return { errorMessage: error.message, isSLOFailure: true }; } // Unknown return { errorMessage: 'Unknown error', isSLOFailure: true }; }; var handleDirectoryGraphQLErrors = exports.handleDirectoryGraphQLErrors = function handleDirectoryGraphQLErrors(errors, traceId) { throw new _errors.DirectoryGraphQLErrors(errors, traceId); }; var handleAGGErrors = exports.handleAGGErrors = function handleAGGErrors(errors, traceId) { throw new _errors.AGGErrors(errors, traceId); };