Skip to content

Conversation

guabu
Copy link
Contributor

@guabu guabu commented Jun 18, 2025

📋 Changes

There are a few cases where we log an error to the console where the necessary context is already in the error returned to the caller for handling. In the places this was not the case, the cause was added and made available to the caller.

📎 References

Fixes: #2107

@guabu guabu requested a review from a team as a code owner June 18, 2025 21:23
Comment on lines +761 to +765
"The access token has expired and there was an error while trying to refresh it.",
new OAuth2Error({
code: e.error,
message: e.error_description
})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than logging the error, the cause is added to the error that is returned to the caller. At that point they can handle the error and choose to log or not.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still feel like it's unfortunate that we lose track of the entire stack trace, is there a way we can retain that? Typically, the cause is set to the original error: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause

httpResponse
);
} catch (err: any) {
console.error(err);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are already returning the cause to the caller here so the error log is not necessary,

await this.discoverAuthorizationServerMetadata();

if (discoveryError) {
console.error(discoveryError);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a redundant log since we already log an error in discoverAuthorizationServerMetadata.

await this.discoverAuthorizationServerMetadata();

if (discoveryError) {
console.error(discoveryError);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a redundant log since we already log an error in discoverAuthorizationServerMetadata.

} catch (e) {
console.error(
`An error occured while performing the discovery request. Please make sure the AUTH0_DOMAIN environment variable is correctly configured — the format must be 'example.us.auth0.com'. issuer=${issuer.toString()}, error:`,
`An error occured while performing the discovery request. issuer=${issuer.toString()}, error:`,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should rarely show up (e.g.: outages or misconfigurations) so I opted to keep this log in to provide some visibility since the errors are not always available for a caller to handler programmatically.

@codecov-commenter
Copy link

codecov-commenter commented Jun 19, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.88%. Comparing base (0139fea) to head (581e555).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2179   +/-   ##
=======================================
  Coverage   82.87%   82.88%           
=======================================
  Files          21       21           
  Lines        2091     2092    +1     
  Branches      372      372           
=======================================
+ Hits         1733     1734    +1     
  Misses        351      351           
  Partials        7        7           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@frederikprijck frederikprijck merged commit 3d0f19e into auth0:main Jun 20, 2025
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error is always printed to console
3 participants