|
| 1 | +# Error Code Convention |
| 2 | + |
| 3 | +## Overview |
| 4 | +This document defines the error code convention used throughout the Asgardeo JavaScript SDK to ensure consistency and maintainability. |
| 5 | + |
| 6 | +## Format |
| 7 | +Error codes follow this format: |
| 8 | +``` |
| 9 | +[{packageName}-]{functionName}-{ErrorCategory}-{SequentialNumber} |
| 10 | +``` |
| 11 | + |
| 12 | +### Components |
| 13 | + |
| 14 | +#### 1. Package Name (Optional) |
| 15 | +- Use when the function might exist in multiple packages or when disambiguation is needed |
| 16 | +- Use the package identifier (e.g., "javascript", "react", "node") |
| 17 | +- Examples: `javascript-`, `react-`, `node-` |
| 18 | + |
| 19 | +#### 2. Function Name |
| 20 | +- Use the exact function name as defined in the code |
| 21 | +- Use camelCase format matching the function declaration |
| 22 | +- Examples: `getUserInfo`, `executeEmbeddedSignUpFlow`, `initializeEmbeddedSignInFlow` |
| 23 | + |
| 24 | +#### 3. Error Category |
| 25 | +Categories represent the type of error: |
| 26 | + |
| 27 | +- **ValidationError**: Input validation failures, missing required parameters, invalid parameter values |
| 28 | +- **ResponseError**: HTTP response errors, network failures, server errors |
| 29 | +- **ConfigurationError**: Configuration-related errors, missing configuration, invalid settings |
| 30 | +- **AuthenticationError**: Authentication-specific errors, token issues, credential problems |
| 31 | +- **AuthorizationError**: Authorization-specific errors, permission denied, access control |
| 32 | +- **NetworkError**: Network connectivity issues, timeout errors |
| 33 | +- **ParseError**: JSON parsing errors, response format issues |
| 34 | + |
| 35 | +#### 4. Sequential Number |
| 36 | +- Three-digit zero-padded format: `001`, `002`, `003`, etc. |
| 37 | +- Start from `001` for each function |
| 38 | +- Increment sequentially within each function |
| 39 | +- Group by error category for readability |
| 40 | + |
| 41 | +## Numbering Strategy |
| 42 | + |
| 43 | +For each function, allocate number ranges by category: |
| 44 | +- **001-099**: ValidationError |
| 45 | +- **100-199**: ResponseError |
| 46 | +- **200-299**: ConfigurationError |
| 47 | +- **300-399**: AuthenticationError |
| 48 | +- **400-499**: AuthorizationError |
| 49 | +- **500-599**: NetworkError |
| 50 | +- **600-699**: ParseError |
| 51 | + |
| 52 | +## Package Prefix Guidelines |
| 53 | + |
| 54 | +Use the package prefix when: |
| 55 | +1. **Multi-package scenarios**: When the same function name exists across different packages |
| 56 | +2. **Public APIs**: For functions that are part of the public API and might be referenced externally |
| 57 | +3. **Complex projects**: In large codebases where disambiguation aids debugging and maintenance |
| 58 | + |
| 59 | +Examples of when to use prefixes: |
| 60 | +- `javascript-executeEmbeddedSignUpFlow-ValidationError-001` (public API function) |
| 61 | +- `react-useAuth-ConfigurationError-201` (React-specific hook) |
| 62 | +- `node-createServer-NetworkError-501` (Node.js-specific function) |
| 63 | + |
| 64 | +## Examples |
| 65 | + |
| 66 | +### With Package Prefix (Recommended for Public APIs) |
| 67 | +```typescript |
| 68 | +// executeEmbeddedSignUpFlow Function (JavaScript package) |
| 69 | +'javascript-executeEmbeddedSignUpFlow-ValidationError-001' // Missing payload |
| 70 | +'javascript-executeEmbeddedSignUpFlow-ValidationError-002' // Invalid flowType |
| 71 | +'javascript-executeEmbeddedSignUpFlow-ResponseError-100' // HTTP error response |
| 72 | +``` |
| 73 | + |
| 74 | +### Without Package Prefix (Internal/Simple Functions) |
| 75 | +```typescript |
| 76 | +// getUserInfo Function (internal utility) |
| 77 | +'getUserInfo-ValidationError-001' // Invalid URL |
| 78 | +'getUserInfo-ValidationError-002' // Missing access token |
| 79 | +'getUserInfo-ResponseError-100' // HTTP error response |
| 80 | +'getUserInfo-ResponseError-101' // Invalid response format |
| 81 | +``` |
| 82 | + |
| 83 | +## Implementation Guidelines |
| 84 | + |
| 85 | +1. **Consistency**: Always use the exact function name in error codes |
| 86 | +2. **Package Prefix**: Use package prefixes for public APIs and when disambiguation is needed |
| 87 | +3. **Documentation**: Document each error code with clear description |
| 88 | +4. **Categorization**: Choose the most appropriate category for each error |
| 89 | +5. **Numbering**: Use the range-based numbering system for better organization |
| 90 | +6. **Future-proofing**: Leave gaps in numbering for future error codes |
| 91 | + |
| 92 | +## Current Implementation Status |
| 93 | + |
| 94 | +### Updated Functions (Following New Convention) |
| 95 | +- ✅ `executeEmbeddedSignUpFlow` - Uses `javascript-` prefix with range-based numbering |
| 96 | + |
| 97 | +### Functions Needing Updates |
| 98 | +- ⏳ `getUserInfo` - Currently uses simple format, needs prefix evaluation |
| 99 | +- ⏳ `initializeEmbeddedSignInFlow` - Currently uses simple format, needs prefix evaluation |
| 100 | +- ⏳ `executeEmbeddedSignInFlow` - Currently uses simple format, needs prefix evaluation |
| 101 | + |
| 102 | +## Migration Notes |
| 103 | + |
| 104 | +When updating existing error codes: |
| 105 | +1. **Evaluate prefix necessity**: Determine if the function needs a package prefix |
| 106 | +2. **Update numbering**: Move to range-based numbering (ValidationError: 001-099, ResponseError: 100-199, etc.) |
| 107 | +3. **Update tests**: Ensure all tests use the new error codes |
| 108 | +4. **Update documentation**: Document the new error codes |
| 109 | +5. **Consider backward compatibility**: If codes are exposed in public APIs, plan migration strategy |
| 110 | + |
| 111 | +## Example Migration |
| 112 | + |
| 113 | +### Before (Old Convention) |
| 114 | +```typescript |
| 115 | +'getUserInfo-ValidationError-001' |
| 116 | +'getUserInfo-ResponseError-001' |
| 117 | +``` |
| 118 | + |
| 119 | +### After (New Convention) |
| 120 | +```typescript |
| 121 | +// Option 1: With prefix (for public API) |
| 122 | +'javascript-getUserInfo-ValidationError-001' |
| 123 | +'javascript-getUserInfo-ResponseError-100' |
| 124 | + |
| 125 | +// Option 2: Without prefix (for internal use) |
| 126 | +'getUserInfo-ValidationError-001' |
| 127 | +'getUserInfo-ResponseError-100' |
| 128 | +``` |
| 129 | + |
| 130 | +## Current Error Code Registry |
| 131 | + |
| 132 | +### executeEmbeddedSignUpFlow (Updated - New Convention) |
| 133 | +- `javascript-executeEmbeddedSignUpFlow-ValidationError-001` - Missing payload |
| 134 | +- `javascript-executeEmbeddedSignUpFlow-ValidationError-002` - Invalid flowType |
| 135 | +- `javascript-executeEmbeddedSignUpFlow-ResponseError-100` - HTTP error response |
| 136 | + |
| 137 | +### getUserInfo (Legacy Format) |
| 138 | +- `getUserInfo-ValidationError-001` - Invalid endpoint URL |
| 139 | +- `getUserInfo-ResponseError-001` - Failed to fetch user info |
| 140 | + |
| 141 | +### initializeEmbeddedSignInFlow (Legacy Format) |
| 142 | +- `initializeEmbeddedSignInFlow-ValidationError-002` - Missing authorization payload |
| 143 | +- `initializeEmbeddedSignInFlow-ResponseError-001` - Authorization request failed |
| 144 | + |
| 145 | +### executeEmbeddedSignInFlow (Legacy Format) |
| 146 | +- `executeEmbeddedSignInFlow-ValidationError-002` - Missing required parameter |
| 147 | +- `initializeEmbeddedSignInFlow-ResponseError-001` - Response error (Note: incorrect function name reference) |
| 148 | + |
| 149 | +## Recommended Actions |
| 150 | + |
| 151 | +1. **Standardize numbering**: Update legacy functions to use range-based numbering |
| 152 | +2. **Fix inconsistencies**: Correct the error code in `executeEmbeddedSignInFlow` that references the wrong function |
| 153 | +3. **Add prefixes**: Evaluate which functions need package prefixes based on their public API status |
| 154 | +4. **Document usage**: Add inline documentation in each file listing the error codes used |
0 commit comments