UNPKG

@atlaskit/profilecard

Version:

A React component to display a card with user information.

105 lines (104 loc) 4.08 kB
import { AGGError, AGGErrors, DirectoryGraphQLError, DirectoryGraphQLErrors } from '../util/errors'; const IGNORED_ERROR_REASONS_DIRECTORY = [ // Error categories from pf-directory 'NotPermitted', 'Gone', 'IdentityUserNotFoundError']; const IGNORE_ERROR_TYPES_AGG = ['IdentityUserNotFoundError', 'TEAMS_FORBIDDEN', 'TEAMS_TEAM_DELETED']; const IGNORE_ERROR_CLASSIFICATIONS_AGG = ['Gone']; function isIgnoredError(error) { if (!error) { return false; } if (error instanceof DirectoryGraphQLError) { return !!error && IGNORED_ERROR_REASONS_DIRECTORY.includes(error.type); } else if (error instanceof AGGError) { return !!error.errorType && IGNORE_ERROR_TYPES_AGG.includes(error.errorType) || !!error.classification && IGNORE_ERROR_CLASSIFICATIONS_AGG.includes(error.classification); } return false; } export const getErrorAttributes = error => { const defaultErrorAttributes = { errorCount: null, errorDetails: null, errorCategory: null, errorType: null, errorPath: null, errorNumber: null, errorStatusCode: null, traceId: null, errorStack: null }; if (error instanceof DirectoryGraphQLErrors) { var _error$traceId; return { ...defaultErrorAttributes, errorMessage: error.message, errorCount: error.errors.length, errorDetails: error.errors.map(getErrorAttributes), isSLOFailure: !error.errors.every(isIgnoredError), traceId: (_error$traceId = error.traceId) !== null && _error$traceId !== void 0 ? _error$traceId : null }; } else if (error instanceof DirectoryGraphQLError) { var _error$errorNumber; return { ...defaultErrorAttributes, errorMessage: error.message, errorCategory: error.category, errorType: error.type, errorPath: error.path, errorNumber: (_error$errorNumber = error.errorNumber) !== null && _error$errorNumber !== void 0 ? _error$errorNumber : null, isSLOFailure: !isIgnoredError(error) }; } else if (error instanceof AGGErrors) { var _error$traceId2; return { ...defaultErrorAttributes, errorMessage: error.message, errorCount: error.errors.length, errorDetails: error.errors.map(getErrorAttributes), isSLOFailure: !error.errors.every(isIgnoredError), traceId: (_error$traceId2 = error.traceId) !== null && _error$traceId2 !== void 0 ? _error$traceId2 : null }; } else if (error instanceof AGGError) { var _error$errorType, _error$statusCode, _error$classification; return { ...defaultErrorAttributes, errorMessage: error.message, errorType: (_error$errorType = error.errorType) !== null && _error$errorType !== void 0 ? _error$errorType : null, errorStatusCode: (_error$statusCode = error.statusCode) !== null && _error$statusCode !== void 0 ? _error$statusCode : null, isSLOFailure: !isIgnoredError(error), errorCategory: (_error$classification = error.classification) !== null && _error$classification !== void 0 ? _error$classification : null }; } 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')) { const causeError = error.cause; if (causeError instanceof DirectoryGraphQLErrors || causeError instanceof AGGErrors) { return getErrorAttributes(causeError); } } return { ...defaultErrorAttributes, errorMessage: error.message, isSLOFailure: false }; } return { ...defaultErrorAttributes, errorMessage: error.message, isSLOFailure: true }; } // Unknown return { ...defaultErrorAttributes, errorMessage: 'Unknown error', isSLOFailure: true }; }; export const handleDirectoryGraphQLErrors = (errors, traceId) => { throw new DirectoryGraphQLErrors(errors, traceId); }; export const handleAGGErrors = (errors, traceId) => { throw new AGGErrors(errors, traceId); };