Skip to content

[I-003] [Tech Debt]: Unify and improve error types #359

Closed

Description

@indpurvesh

Priority: High
Phase: Phase 1 (Code Quality)
Dependencies: #357


📝 User Story

As a developer,
I want to have a single, consistent error type across the codebase,
So that error handling is predictable and API consumers receive uniform error responses.


🎯 Scope & Requirements

  • Consolidate the duplicate ErrorResponse structs: one in error.rs (imported from core::domain::entities::error_message) and another in auth_middleware.rs (line 14)
  • Ensure all API errors return a consistent JSON shape: { "status": false, "errors": [...] } or { "status": false, "message": "..." }
  • Remove format!("error 500: {:?}", err) from the catch-all IntoResponse impl (line 95-96 in error.rs) — never expose internal error details
  • Add a Forbidden variant to the Error enum for authorization failures
  • Consider using thiserror or anyhow for cleaner derive-based error impls

✅ Acceptance Criteria

  • Given a 500 error, When the client reads the response body, Then it sees a generic error message, not a Rust debug-printed enum.
  • Given any API error, When the response is parsed as JSON, Then it matches the unified error schema.
  • Given the codebase, When searching for struct ErrorResponse, Then exactly one definition exists.

🛠️ Technical Context / Notes

  • Backend: Axum IntoResponse impl in error.rs
  • The middleware currently defines its own ErrorResponse (line 12-19 of auth_middleware.rs) that differs from the domain ErrorResponse.

📋 Task Checklist

  • Merge ErrorResponse definitions into a single canonical type
  • Update IntoResponse for Error to never leak internal details
  • Add Forbidden variant
  • Update all handler error returns to use the unified type
  • Write unit tests for error serialization

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions