Skip to content

Add comprehensive error handling to Player API creation endpoints#65

Draft
sei-awelle wants to merge 3 commits intomainfrom
feature/improve-error-handling
Draft

Add comprehensive error handling to Player API creation endpoints#65
sei-awelle wants to merge 3 commits intomainfrom
feature/improve-error-handling

Conversation

@sei-awelle
Copy link
Copy Markdown
Contributor

Summary

  • Enhanced error handling for View, Team, User, Application, and ApplicationInstance creation
  • Added validation and early foreign key validation
  • Implemented PostgreSQL-specific error handling with detailed constraint messages
  • Added comprehensive structured logging

Changes

  • Views/Create.cs: Name validation, PostgreSQL error handling, logging
  • Teams/Create.cs: Name and ViewId validation, early FK checks, error handling
  • Users/Create.cs: Name validation, comprehensive error handling
  • Applications/Create.cs: Name and ViewId validation, FK validation, error handling
  • Applications/CreateApplicationInstance.cs: TeamId and ApplicationId validation, FK checks

Benefits

  • Clear, actionable error messages during Blueprint MSEL deployment to Player
  • Database constraint violations caught with meaningful context
  • Foreign key issues identified early before database operations
  • Better debugging with structured logging (INFO, WARNING, ERROR)
  • Improved reliability for integration operations

Testing

  • All endpoints compile successfully
  • Tested error paths with invalid data
  • Verified logging output
  • Confirmed no regression on success paths

@sei-awelle sei-awelle requested a review from a team as a code owner February 27, 2026 18:47
Simplified approach that focuses on what matters:
- Parse PostgreSQL error codes (23505, 23503, 23514) into actionable messages
- Keep input validation for early failure detection
- Let ExceptionMiddleware handle all logging automatically

Changes:
- **Views/Create.cs**: PostgreSQL error handling, name validation
- **Teams/Create.cs**: PostgreSQL error handling, ViewId/RoleId validation
- **Users/Create.cs**: PostgreSQL error handling, name validation
- **Applications/Create.cs**: PostgreSQL error handling, ViewId validation
- **ApplicationInstance/Create.cs**: PostgreSQL error handling, FK validation

Benefits:
- Clear error messages like 'Invalid ViewId X. The View does not exist.'
- ExceptionMiddleware logs all exceptions with full context
- Less code, same debugging capability
@sei-awelle sei-awelle force-pushed the feature/improve-error-handling branch from 372949b to 05e7f1b Compare February 27, 2026 19:22
sei-awelle and others added 2 commits February 27, 2026 20:01
Centralized database error handling in middleware:
- Added TransformPostgresException method to ExceptionMiddleware
- Removed all try/catch blocks from Create handlers
- Removed unused logger parameters from handler constructors
- Removed unused using statements (Microsoft.Extensions.Logging, Npgsql)

Simplified handlers for:
- Applications/Create.cs: Removed 32 lines of error handling
- Teams/Create.cs: Removed 33 lines of error handling
- Users/Create.cs: Removed 32 lines of error handling
- Views/Create.cs: Removed 35 lines of error handling

This matches the pattern established in Caster API PR #77.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Sanitize database error messages for security:
- Log detailed PostgreSQL info (table, constraint, message) for debugging
- Always return generic user-friendly messages to users
- Never expose database internals to prevent information leakage
- Matches security improvements in Caster API PR #77
@sei-awelle sei-awelle marked this pull request as draft March 1, 2026 03:51
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.

1 participant