ban-bugResult Pattern

Handle GL IAM errors using the unified Result pattern.

circle-info

When to use: GL IAM Gateway operations return a Result - learn to handle success and errors consistently.

Architecture Note

GL IAM uses a hybrid error handling approach:

Layer
Pattern
Rationale

IAMGateway (public API)

Result Pattern

Type-safe, explicit error handling for consumers

Providers (internal)

Exceptions

Simpler implementation, idiomatic Python

The Gateway wraps provider exceptions into Results, giving you the best of both worlds: clean Result-based APIs for your code, while providers use natural Python exception handling internally.

chevron-rightPrerequisiteshashtag
  • Completed Login

  • Basic understanding of error handling

5-Line Core

result = await gateway.authenticate(credentials, organization_id="default")
if result.is_ok:
    user, token = result.unwrap()
else:
    print(f"Error: {result.error.code}")

Result States

State
Check
Access

Success

result.is_ok

result.value or result.unwrap()

Error

result.is_err

result.error

MFA Required

result.requires_mfa

result.mfa_challenge_id

Step-by-Step

1

Check Success

2

Handle Errors

3

Pattern Match Errors

4

Handle MFA

5

Expected Output

Or on error:

circle-check

Complete Example

Create result_pattern.py:

Run it:

Expected output:

Error Codes Reference

Category
Codes

Auth

AUTHENTICATION_FAILED, INVALID_CREDENTIALS, ACCOUNT_LOCKED

Token

INVALID_TOKEN, SESSION_EXPIRED, SESSION_NOT_FOUND

User

USER_NOT_FOUND, USER_ALREADY_EXISTS

Config

NO_AUTH_PROVIDER, NO_USER_STORE, NO_SESSION_PROVIDER

FastAPI Integration

Common Pitfalls

Pitfall
Solution

Calling unwrap() without checking

Always check is_ok first

Ignoring MFA state

Check requires_mfa for auth results

Generic error handling

Pattern match on error codes

Last updated

Was this helpful?