Skip to main content

Error Handling

Proper error handling is crucial for creating robust authentication flows that provide clear feedback to users while maintaining security. Scute provides comprehensive error handling utilities to help you manage various failure scenarios gracefully.

Overview

Scute’s error handling system is designed to:
  • Provide meaningful error messages that help users understand what went wrong
  • Maintain security by not exposing sensitive information in error messages
  • Enable proper logging for debugging and monitoring
  • Support different error types for various authentication scenarios
  • Offer retry mechanisms for transient failures

Error Types

Scute categorizes errors into several types to help you handle them appropriately:

Custom Scute Errors

  • identifier-not-recognized: The provided identifier (email/username) is not recognized in the system
  • identifier-already-exists: A user with this identifier already exists during registration
  • identifier-invalid: The identifier format is invalid (e.g., malformed email)
  • new-device: Authentication attempt from a new/unrecognized device
  • login-required: User must be logged in to access the resource
  • invalid-auth-token: The authentication token is invalid or expired
  • unknown-sign-in: An unknown error occurred during sign-in
  • invalid-magic-link: The magic link is invalid, expired, or already used

HTTP Errors

  • 4xx Client Errors: Bad request, unauthorized, forbidden, not found errors
  • 5xx Server Errors: Internal server errors, service unavailable
  • 502, 503, 504: Network-related errors (Bad Gateway, Service Unavailable, Gateway Timeout)

WebAuthn Errors

  • ERROR_CEREMONY_ABORTED: The WebAuthn ceremony was aborted by the user
  • ERROR_INVALID_DOMAIN: The current domain is invalid for WebAuthn
  • ERROR_INVALID_RP_ID: The Relying Party ID is invalid for this domain
  • ERROR_INVALID_USER_ID_LENGTH: User ID must be between 1 and 64 characters
  • ERROR_MALFORMED_PUBKEYCREDPARAMS: Public key credential parameters are malformed
  • ERROR_AUTHENTICATOR_GENERAL_ERROR: General authenticator error
  • ERROR_AUTHENTICATOR_MISSING_DISCOVERABLE_CREDENTIAL_SUPPORT: Authenticator doesn’t support discoverable credentials
  • ERROR_AUTHENTICATOR_MISSING_USER_VERIFICATION_SUPPORT: Authenticator doesn’t support user verification
  • ERROR_AUTHENTICATOR_PREVIOUSLY_REGISTERED: The authenticator was previously registered
  • ERROR_AUTHENTICATOR_NO_SUPPORTED_PUBKEYCREDPARAMS_ALG: No supported algorithms in pubKeyCredParams
  • ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY: Error passed through from platform (check cause property)

Technical Errors

  • TechnicalError: Internal technical errors that should be handled gracefully

Basic Error Handling

Here’s how to implement basic error handling with Scute:

Advanced Error Handling Patterns

Error Boundary for React Applications

Implement an error boundary to catch and handle authentication errors at the component level:

Retry Logic with Exponential Backoff

Implement smart retry logic for transient errors:

Form Validation with Error Display

Create a comprehensive form handler with error display:

Error Monitoring and Logging

Production Error Tracking

Set up comprehensive error tracking for production environments:

Best Practices

1. User-Friendly Messages

Always provide clear, actionable error messages to users:

2. Security Considerations

Never expose sensitive information in error messages:

3. Graceful Degradation

Provide fallback functionality when possible:

4. Error Recovery

Always provide users with a path to recover from errors:

Testing Error Scenarios

Create comprehensive tests for your error handling:
By implementing comprehensive error handling following these patterns, you’ll create a robust authentication system that provides excellent user experience even when things go wrong.