Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion src/errors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,13 @@ export enum AccessTokenErrorCode {

export class AccessTokenError extends SdkError {
public code: string;
public cause?: OAuth2Error;

constructor(code: string, message: string) {
constructor(code: string, message: string, cause?: OAuth2Error) {
super(message);
this.name = "AccessTokenError";
this.code = code;
this.cause = cause;
}
}

Expand Down
15 changes: 7 additions & 8 deletions src/server/auth-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import { AbstractSessionStore } from "./session/abstract-session-store.js";
import { TransactionState, TransactionStore } from "./transaction-store.js";
import { filterDefaultIdTokenClaims } from "./user.js";


export type BeforeSessionSavedHook = (
session: SessionData,
idToken: string | null
Expand Down Expand Up @@ -733,7 +732,6 @@ export class AuthClient {
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.

return [discoveryError, null];
}

Expand All @@ -757,11 +755,14 @@ export class AuthClient {
refreshTokenRes
);
} catch (e: any) {
console.error(e);
return [
new AccessTokenError(
AccessTokenErrorCode.FAILED_TO_REFRESH_TOKEN,
"The access token has expired and there was an error while trying to refresh it. Check the server logs for more information."
"The access token has expired and there was an error while trying to refresh it.",
new OAuth2Error({
code: e.error,
message: e.error_description
})
Comment on lines +761 to +765
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

),
null
];
Expand Down Expand Up @@ -815,7 +816,7 @@ export class AuthClient {
return [null, authorizationServerMetadata];
} 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.

e
);
return [
Expand Down Expand Up @@ -1106,7 +1107,6 @@ export class AuthClient {
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.

return [discoveryError, null];
}

Expand All @@ -1130,11 +1130,10 @@ export class AuthClient {
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,

return [
new AccessTokenForConnectionError(
AccessTokenForConnectionErrorCode.FAILED_TO_EXCHANGE,
"There was an error trying to exchange the refresh token for a connection access token. Check the server logs for more information.",
"There was an error trying to exchange the refresh token for a connection access token.",
new OAuth2Error({
code: err.error,
message: err.error_description
Expand Down