Skip to content

fix: callback error message and code#1665

Open
emlimlf wants to merge 4 commits intomainfrom
fix/callback-error-code
Open

fix: callback error message and code#1665
emlimlf wants to merge 4 commits intomainfrom
fix/callback-error-code

Conversation

@emlimlf
Copy link
Collaborator

@emlimlf emlimlf commented Feb 10, 2026

In this PR

Changed the catch block throw error message and code for the authentication callback.

Ticket

IN-957

Signed-off-by: Efren Lim <elim@linuxfoundation.org>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates the authentication callback API error handling so the catch block can throw an error with a more specific status code/message (instead of always returning a generic 500).

Changes:

  • Adds logic in the callback handler catch block to derive statusCode/statusMessage from an H3Error.
  • Changes the default error code/message used when the caught error is not an H3Error.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 154 to 161
if (error instanceof H3Error) {
errorMessage = error.statusMessage || error.message || 'Authentication callback error';
errorCode = error.statusCode;
}

throw createError({
statusCode: 500,
statusMessage: 'Authentication callback error',
statusCode: errorCode,
statusMessage: errorMessage,
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

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

In the H3Error branch, error.statusCode may be undefined (it’s optional in some H3 error shapes). Passing that through as statusCode can lead to inconsistent responses. Consider defaulting with error.statusCode ?? 500 (or another explicit fallback) before calling createError.

Copilot uses AI. Check for mistakes.
Comment on lines 152 to 161
let errorMessage = 'Authentication callback error';
let errorCode = 401;
if (error instanceof H3Error) {
errorMessage = error.statusMessage || error.message || 'Authentication callback error';
errorCode = error.statusCode;
}

throw createError({
statusCode: 500,
statusMessage: 'Authentication callback error',
statusCode: errorCode,
statusMessage: errorMessage,
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

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

The catch-all branch now forwards error.message/statusMessage to the HTTP response. Errors thrown by openid-client and other libraries can include internal details that shouldn’t be exposed to clients. Consider returning a generic statusMessage for unexpected errors and only surfacing curated/auth-specific messages (while keeping the detailed error logged server-side).

Copilot uses AI. Check for mistakes.
deleteCookie(event, 'auth_refresh_token');

let errorMessage = 'Authentication callback error';
let errorCode = 401;
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

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

Defaulting to 401 for any non-H3Error exception will classify unexpected server-side failures (e.g., Auth0 discovery/network errors thrown as plain Error) as an auth failure, which can make debugging/monitoring harder and may be semantically incorrect. Consider defaulting to 500 and only using 401 for clearly identified authentication/authorization errors.

Suggested change
let errorCode = 401;
let errorCode = 500;

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

Choose a reason for hiding this comment

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

i agree with that suggestion

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah I agree as well. The default should be 500. Then we should be able to throw specific error codes such as 401 when we know it's exactly for authentication/authorization errors.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

Comment on lines 154 to 156
if (error instanceof H3Error) {
errorMessage = error.statusMessage || error.message || 'Authentication callback error';
errorCode = error.statusCode;
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

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

H3Error is referenced as a runtime value in instanceof H3Error, but it is not imported in this file. This will fail TypeScript compilation (and at runtime H3Error will be undefined). Import H3Error from h3 (or use a different H3 error guard that doesn’t rely on an unimported symbol).

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

@gaspergrom gaspergrom left a comment

Choose a reason for hiding this comment

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

i think copilot comments make sense

deleteCookie(event, 'auth_refresh_token');

let errorMessage = 'Authentication callback error';
let errorCode = 401;
Copy link
Collaborator

Choose a reason for hiding this comment

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

i agree with that suggestion

deleteCookie(event, 'auth_refresh_token');

let errorMessage = 'Authentication callback error';
let errorCode = 401;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah I agree as well. The default should be 500. Then we should be able to throw specific error codes such as 401 when we know it's exactly for authentication/authorization errors.

emlimlf and others added 2 commits February 11, 2026 12:47
Signed-off-by: Efren Lim <elim@linuxfoundation.org>
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.

3 participants

Comments