Skip to content

Conversation

subhankarmaiti
Copy link
Contributor

@subhankarmaiti subhankarmaiti commented Aug 4, 2025

This PR unifies error handling across Native (iOS/Android) and Web platforms, providing a consistent, platform-agnostic model that addresses the developer experience issues raised in #923.

Key Changes:

  • Platform-Agnostic Errors: CredentialsManagerError and the new WebAuthError now map platform-specific and web error codes to a single, consistent set of codes.
  • New Typed WebAuthError: Introduces a WebAuthError class with a .type property (e.g., 'USER_CANCELLED') for easy, reliable error identification, eliminating the need for Platform.OS checks.
  • Native SDK Upgrades: Updates auth0-android to 3.8.0 and Auth0.swift to 2.13.0 to leverage their latest error reporting capabilities.
  • Updated Documentation: The README.md is updated with new error tables and "Before/After" code examples to guide developers on the new, simplified approach.

Fixes: #923, #1260

@subhankarmaiti subhankarmaiti changed the title Platform agnostic error feat: Unify and Improve Error Handling Across Platforms Aug 19, 2025
@subhankarmaiti subhankarmaiti changed the title feat: Unify and Improve Error Handling Across Platforms feat: unify and improve error handling across platforms Aug 19, 2025
@subhankarmaiti subhankarmaiti marked this pull request as ready for review August 19, 2025 04:36
@subhankarmaiti subhankarmaiti requested a review from a team as a code owner August 19, 2025 04:36
@pmathew92 pmathew92 requested a review from Copilot August 19, 2025 05:27
Copy link

@Copilot 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

This PR unifies error handling across Native (iOS/Android) and Web platforms by introducing platform-agnostic error classes and standardized error codes. The changes address developer experience issues by eliminating the need for platform-specific error handling code.

  • Introduces WebAuthError class with typed error codes for consistent error identification across platforms
  • Adds platform-agnostic CredentialsManagerError mapping for web platform compatibility
  • Updates native SDK dependencies to leverage improved error reporting capabilities

Reviewed Changes

Copilot reviewed 13 out of 14 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/core/models/WebAuthError.ts New error class that maps platform-specific codes to unified error types
src/core/models/CredentialsManagerError.ts Extended error mappings to include web platform error codes
src/platforms/web/adapters/WebWebAuthProvider.ts Updated to throw WebAuthError instead of AuthError for consistent handling
src/platforms/web/adapters/WebCredentialsManager.ts Updated to throw CredentialsManagerError for platform consistency
src/platforms/native/adapters/NativeWebAuthProvider.ts Wrapped native errors in WebAuthError for unified error handling
android/build.gradle Updated auth0-android dependency from 3.2.1 to 3.8.0
A0Auth0.podspec Updated Auth0.swift dependency from 2.10 to 2.13
README.md Added comprehensive error handling documentation with before/after examples

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Contributor

@pmathew92 pmathew92 left a comment

Choose a reason for hiding this comment

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

@subhankarmaiti Could you add more test cases to validate these changes for different platform specific error scenarios ?

| `INVALID_CREDENTIALS` | `INVALID_CREDENTIALS` | | |
| `NO_CREDENTIALS` | `NO_CREDENTIALS` | `noCredentials` | `login_required` |
| `NO_REFRESH_TOKEN` | `NO_REFRESH_TOKEN` | `noRefreshToken` |
| `RENEW_FAILED` | `RENEW_FAILED` | `renewFailed` | `missing_refresh_token`, `invalid_grant`,`consent_required` |
Copy link
Contributor

Choose a reason for hiding this comment

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

invalid_grant,consent_required Have we thought about how to handle when web returns these two errors when logging in the first time and not renewing ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@pmathew92 This error won’t occur during login. It comes from the getTokenSilently call, which is why we map it as RENEW_FAILED.

Copy link
Contributor

Choose a reason for hiding this comment

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

@subhankarmaiti Ok. But I would still suggest to cross check before merging the same

@pmathew92
Copy link
Contributor

pmathew92 commented Aug 21, 2025

@subhankarmaiti Could we add few more test cases where all 3 platforms send different error types

@subhankarmaiti subhankarmaiti merged commit 484579a into master Aug 25, 2025
3 checks passed
@subhankarmaiti subhankarmaiti deleted the SDK-5700-platform-agnostic-error branch August 25, 2025 11:24
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.

Platform-agnostic errors and types
2 participants