Skip to content

Conversation

@grdsdev
Copy link
Collaborator

@grdsdev grdsdev commented Dec 12, 2025

Summary

Implements Phase 1.1 of the roadmap by adding structured error handling to the auth-go library.

Changes

  • ✅ Add AuthError type in types/error.go with StatusCode, Message, ErrorCode, and Details fields
  • ✅ Add handleErrorResponse helper function in endpoints/errors.go to parse API error responses
  • ✅ Update all 23 endpoint files to use the new error handling instead of fmt.Errorf
  • ✅ Remove unused imports (fmt, io) from endpoint files
  • ✅ Preserve backward-compatible error message format ("response status code %d: %s")

Backward Compatibility

This is a non-breaking change:

  • ✅ Errors still implement the error interface
  • ✅ Error message format matches the previous format exactly
  • ✅ Existing code continues to work without modification
  • ✅ Users can now opt-in to structured error inspection using errors.As()

Usage Example

resp, err := client.SignUp(req)
if err != nil {
// Still works (error is still an error, same message format)
log.Printf("Error: %v", err)

// NEW: Can now inspect structured errors
var authErr *types.AuthError
if errors.As(err, &authErr) {
    if authErr.StatusCode == 429 {
        // Handle rate limiting
    }
    log.Printf("Error code: %s", authErr.ErrorCode)
    log.Printf("Details: %v", authErr.Details)
}

}

Implements Phase 1.1 of the roadmap by adding structured error handling.

- Add AuthError type in types/error.go with StatusCode, Message, ErrorCode, and Details fields
- Add handleErrorResponse helper function in endpoints/errors.go to parse API error responses
- Update all 23 endpoint files to use the new error handling instead of fmt.Errorf
- Maintains backward compatibility - errors still implement the error interface
- Users can now use errors.As() to inspect structured errors

This is a non-breaking change as errors are still returned as error interface,
but users can now opt-in to structured error inspection.

Closes #ROADMAP Phase 1.1
Update AuthError.Error() to match the previous fmt.Errorf format
('response status code %d: %s') to ensure backward compatibility
with code that may do string matching on error messages.

The error type is still AuthError (for structured access via errors.As),
but the message format remains the same for compatibility.
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.

2 participants