Skip to content

feat(api) add consistent error codes for API responses#745

Open
Krishnavamsi-codes wants to merge 1 commit into
imDarshanGK:mainfrom
Krishnavamsi-codes:issue-509-consistent-error-codes
Open

feat(api) add consistent error codes for API responses#745
Krishnavamsi-codes wants to merge 1 commit into
imDarshanGK:mainfrom
Krishnavamsi-codes:issue-509-consistent-error-codes

Conversation

@Krishnavamsi-codes
Copy link
Copy Markdown

Description

This PR implements consistent error codes for API responses across the backend.

Changes made

  • Added centralized exception handling via backend/app/exceptions.py

  • Introduced an ErrorCode enum with standardized string-based error codes

  • Added an ErrorResponse schema for consistent API error responses

  • Registered global handlers for:

    • HTTPException
    • RequestValidationError
    • Unhandled exceptions
  • Updated middleware responses to include error codes

  • Standardized API error responses to the format:

{
  "error": "error_code",
  "detail": "Human-readable message"
}
  • Preserved existing HTTP status codes and detail messages
  • Updated backend tests to validate the new error response schema

Related Issue

Fixes #509

Type of change

  • Bug fix
  • New feature / enhancement
  • Documentation update
  • Test addition
  • Refactor

Checklist

  • I have read CONTRIBUTING.md
  • My branch is up to date with main
  • I have run pytest -v and all tests pass
  • I have not introduced duplicate issues or features
  • My PR title follows the format: feat/fix/docs/test: short description
  • I have added tests for new features (Level 2 and 3 issues)
  • No hardcoded secrets or API keys in my code
  • This PR is linked to a GSSoC 2026 issue

Screenshots (if frontend change)

N/A

Test evidence

pytest -v

==================== test session starts ====================
372 passed, 9 warnings in 17.98s
==================== test session finished ==================

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.

Add consistent error codes for API responses

1 participant