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

Handle fetch exceptions #1487

Merged
merged 3 commits into from
Jan 24, 2024

Conversation

denysoblohin-okta
Copy link
Contributor

@denysoblohin-okta denysoblohin-okta commented Jan 18, 2024

fetch can throw exceptions: https://developer.mozilla.org/en-US/docs/Web/API/fetch#exceptions

formatError currently will return AuthApiError with xhr property set to TypeError object.
generateIdxAction will try to parse xhr as JSON and will trigger error SyntaxError: "undefined" is not valid JSON

You can reproduce with SIW playground with mock authenticator-enroll-select-authenticator-with-skip having incorrect url http://localhost:3000:1802/idp/idx/cancel. Clicking on Back to sign in will trigger error SyntaxError: "undefined" is not valid JSON instead of OAuthError: Failed to execute 'fetch' on 'Window': Failed to parse URL from http://localhost:3000:1802/idp/idx/cancel

Issue for SIW: OKTA-668419

if (error instanceof Error) {
// fetch() can throw exceptions
// see https://developer.mozilla.org/en-US/docs/Web/API/fetch#exceptions
return new OAuthError('fetch_error', error.message);
Copy link
Contributor

Choose a reason for hiding this comment

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

how about use AuthApiError here?

Copy link
Contributor

@shuowu-okta shuowu-okta left a comment

Choose a reason for hiding this comment

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

approved with a comment

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