diff --git a/reverse_engineering/databaseService/helpers/errorService.js b/reverse_engineering/databaseService/helpers/errorService.js index cb18d5e..d49d316 100644 --- a/reverse_engineering/databaseService/helpers/errorService.js +++ b/reverse_engineering/databaseService/helpers/errorService.js @@ -62,36 +62,57 @@ const getClientIdFromErrorMessage = ({ message }) => { return clientIdWithoutQuotes; }; +/** + * + * @param {{error}} param + * @returns {object[]} + */ +const getOriginalErrors = ({ error }) => { + const originalErrors = error?.originalError?.errors; + if (originalErrors) { + return originalErrors; + } + + const originalError = error?.originalError; + if (originalError) { + return [originalError]; + } + + return []; +}; + /** * * @param {{error: object}} param * @returns {object} */ const prepareError = ({ error }) => { - const originalErrors = error?.originalError?.errors; - if (!originalErrors || originalErrors?.length === 0) { + const originalErrors = getOriginalErrors({ error }); + if (!originalErrors.length) { return error; } const initialErrorDataIndex = originalErrors.length - 1; const initialError = originalErrors[initialErrorDataIndex]; + const fullStackTrace = originalErrors.map(({ stack }) => stack).join('\n\n'); + const isInitialErrorConsentRequiredError = isConsentRequiredError(initialError); if (isInitialErrorConsentRequiredError) { const clientId = getClientIdFromErrorMessage({ message: initialError.message }); const newErrorMessage = getConsentRequiredErrorMessage({ clientId }); - return updateErrorMessageAndStack({ error, newMessage: newErrorMessage, newStackTrace: initialError.stack }); + return updateErrorMessageAndStack({ error, newMessage: newErrorMessage, newStackTrace: fullStackTrace }); } const isInitialErrorDisabledPublicClientFlowsError = isDisabledPublicClientFlowsError(initialError); if (isInitialErrorDisabledPublicClientFlowsError) { const newErrorMessage = 'You need to allow Public client flows for the Entra ID application'; - return updateErrorMessageAndStack({ error, newMessage: newErrorMessage, newStackTrace: initialError.stack }); + return updateErrorMessageAndStack({ error, newMessage: newErrorMessage, newStackTrace: fullStackTrace }); } - return error; + return updateErrorMessageAndStack({ error, newMessage: initialError.message, newStackTrace: fullStackTrace }); }; module.exports = {