Skip to content

Add comprehensive error handling to Blueprint API creation endpoints#148

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

Add comprehensive error handling to Blueprint API creation endpoints#148
sei-awelle wants to merge 5 commits intomainfrom
feature/improve-error-handling

Conversation

@sei-awelle
Copy link
Copy Markdown
Contributor

Summary

  • Enhanced error handling for MSEL, Team, and Card creation operations
  • Added validation for required fields with early FK validation
  • Implemented PostgreSQL-specific error handling with detailed messages
  • Added comprehensive structured logging

Changes

  • MselService.cs:

    • Name validation
    • PostgreSQL error handling (23505, 23503, 23514)
    • Detailed logging for MSEL creation
  • TeamService.cs:

    • Name and MselId validation
    • Early FK validation for MselId
    • PostgreSQL constraint handling
    • Comprehensive logging
  • CardService.cs:

    • Name validation
    • Optional MselId FK validation
    • PostgreSQL error handling
    • Structured logging

Benefits

  • Clear, actionable error messages during MSEL creation and deployment
  • Database constraint violations caught with meaningful context
  • Foreign key issues identified before reaching database
  • Better debugging with structured logging (INFO, WARNING, ERROR)
  • Improved visibility into creation failures during integration pushes
  • Better user experience when MSEL deployment encounters issues

Testing

  • Blueprint.Api compiles successfully
  • Tested error handling paths
  • Confirmed logging output is appropriate
  • No regression on success paths

@sei-awelle sei-awelle requested a review from a team as a code owner February 27, 2026 18:47
Comment thread Blueprint.Api/Services/CardService.cs Fixed
Comment thread Blueprint.Api/Services/CardService.cs Fixed
Comment thread Blueprint.Api/Services/CardService.cs Fixed
Comment thread Blueprint.Api/Services/CardService.cs Fixed
Comment thread Blueprint.Api/Services/MselService.cs Fixed
Comment thread Blueprint.Api/Services/MselService.cs Fixed
Comment thread Blueprint.Api/Services/TeamService.cs Fixed
Comment thread Blueprint.Api/Services/TeamService.cs Fixed
Comment thread Blueprint.Api/Services/TeamService.cs Fixed
Comment thread Blueprint.Api/Services/TeamService.cs Fixed
- Enhanced MselService.CreateAsync with:
  - Name validation
  - PostgreSQL error handling (23505, 23503, 23514)
  - Detailed logging for create operations

- Enhanced TeamService.CreateAsync with:
  - Name and MselId validation
  - Early FK validation for MselId
  - PostgreSQL error handling for all constraint violations
  - Comprehensive logging

- Enhanced CardService.CreateAsync with:
  - Name validation
  - Optional MselId FK validation
  - PostgreSQL error handling
  - Improved debugging with structured logging

- Consistent error messages across all services
- Better visibility into creation failures during MSEL deployment
For consistency with other APIs:
- Created ExceptionMiddleware with PostgreSQL error transformation
- Registered in Startup.Configure (runs earlier in pipeline)
- Removed JsonExceptionFilter registration from MVC
- Removed UseDeveloperExceptionPage

Simplified services by removing all try/catch blocks:
- MselService.CreateAsync: -33 lines
- TeamService.CreateAsync: -37 lines
- CardService.CreateAsync: -34 lines

Sanitized error messages:
- Log detailed PostgreSQL info for debugging
- Always return generic messages to users
- Never expose database internals

Matches architecture in Caster PR #77, Player PR #65, Gallery PR #57
Replaced by ExceptionMiddleware for consistency with other APIs
@sei-awelle sei-awelle force-pushed the feature/improve-error-handling branch from 3632bfa to 04026be Compare February 28, 2026 15:32
Fetch all PlayerApplicationTeams upfront instead of querying inside the loop for each application. This reduces database round trips while maintaining sequential API call processing.
@sei-awelle sei-awelle marked this pull request as draft March 1, 2026 03:53
  - Resolved conflicts in IntegrationPlayerExtensions (adopted parallel batching)
  - Added logging for team creation in TeamService
  - Integrated CITE team type and scoring model migrations
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.

3 participants