UNPKG

@atlaskit/profilecard

Version:

A React component to display a card with user information.

102 lines (101 loc) 5.17 kB
import _defineProperty from "@babel/runtime/helpers/defineProperty"; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } import { AGGError, AGGErrors, DirectoryGraphQLError, DirectoryGraphQLErrors } from '../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 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; } var _getErrorAttributes = function getErrorAttributes(error) { var 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 _objectSpread(_objectSpread({}, 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 _objectSpread(_objectSpread({}, 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 _objectSpread(_objectSpread({}, 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 _objectSpread(_objectSpread({}, 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')) { var causeError = error.cause; if (causeError instanceof DirectoryGraphQLErrors || causeError instanceof AGGErrors) { return _getErrorAttributes(causeError); } } return _objectSpread(_objectSpread({}, defaultErrorAttributes), {}, { errorMessage: error.message, isSLOFailure: false }); } return _objectSpread(_objectSpread({}, defaultErrorAttributes), {}, { errorMessage: error.message, isSLOFailure: true }); } // Unknown return _objectSpread(_objectSpread({}, defaultErrorAttributes), {}, { errorMessage: 'Unknown error', isSLOFailure: true }); }; export { _getErrorAttributes as getErrorAttributes }; export var handleDirectoryGraphQLErrors = function handleDirectoryGraphQLErrors(errors, traceId) { throw new DirectoryGraphQLErrors(errors, traceId); }; export var handleAGGErrors = function handleAGGErrors(errors, traceId) { throw new AGGErrors(errors, traceId); };