Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HCK: improved logs to get the full stack trace from original (initial) RE error #115

Merged
merged 2 commits into from
Oct 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions reverse_engineering/databaseService/helpers/errorService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down