Skip to content

Duplicate Key Handling Issue in Obligation Creation #127

@ChayanDass

Description

@ChayanDass

Duplicate Key Handling Issue in Obligation Creation


Description:

The API currently returns inconsistent error responses when encountering duplicate topic or text keys while creating an obligation.


Current Behavior:

  • Duplicate topic: Returns 409 Conflict with a descriptive message.
  • Duplicate text: Returns 400 Bad Request with a generic message.

Expected Behavior:

  • When both topic and text are duplicates, the API should return a single, combined response:
{
  "status": 409,
  "message": "Duplicate keys error",
  "error": "Obligation with topic '...' and text '...' already exists",
  "path": "/api/v1/obligations",
  "timestamp": "2025-03-24T22:54:33+05:30"
}
  • When only the topic is duplicated:
{
  "status": 409,
  "message": "Duplicate topic error",
  "error": "Obligation with topic '...' already exists",
  "path": "/api/v1/obligations",
  "timestamp": "2025-03-24T22:54:33+05:30"
}
  • When only the text is duplicated:
{
  "status": 409,
  "message": "Duplicate text error",
  "error": "Obligation with text '...' already exists",
  "path": "/api/v1/obligations",
  "timestamp": "2025-03-24T22:54:33+05:30"
}

Solution:

  • Use 409 Conflict when either topic, text, or both are duplicates.
  • Return specific responses based on the duplicate case.

Impact:

  • Improved API consistency.
  • Easier error handling for clients.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions