Skip to content

Implement Centralized Custom Error Handling Logic. #683

@Mahadeb369

Description

@Mahadeb369

The project currently relies on built-in error classes such as ValidationError and GraphQLError without a unified structure for handling or formatting errors.

Proposed Enhancement

Introduce a centralized custom error-handling mechanism to:

  • Standardize error responses across all modules
  • Improve debugging and client-side error parsing
  • Ensure consistent use of error codes and messages

Benefits

  • Easier maintenance and scalability
  • Clearer and more predictable API responses
  • Simplified client integration and error tracking

Steps to Reproduce

Below are examples of inconsistent error responses across different scenarios:

Failed Login

{
  "errors": [
    {
      "message": "GraphQlValidationError",
      "locations": [{ "line": 2, "column": 3 }],
      "path": ["tokenAuth"],
      "extensions": {
        "non_field_errors": [
          {
            "message": "No active account found with the given credentials",
            "code": "no_active_account"
          }
        ]
      }
    }
  ],
  "data": { "tokenAuth": null }
}

Failed Signup

{
  "errors": [
    {
      "message": "GraphQlValidationError",
      "locations": [{ "line": 2, "column": 3 }],
      "path": ["signUp"],
      "extensions": {
        "email": [
          {
            "message": "This field must be unique.",
            "code": "unique"
          }
        ]
      }
    }
  ],
  "data": { "signUp": null }
}

Invalid Access Token

{
  "detail": {
    "message": "Given token not valid for any token type",
    "code": "token_not_valid"
  },
  "code": {
    "message": "token_not_valid",
    "code": "token_not_valid"
  },
  "messages": [
    {
      "token_class": {
        "message": "AccessToken",
        "code": "token_not_valid"
      },
      "token_type": {
        "message": "access",
        "code": "token_not_valid"
      },
      "message": {
        "message": "Token is invalid or expired",
        "code": "token_not_valid"
      }
    }
  ],
  "is_error": true
}

System Info

Ubuntu 22.04 (x86_64)

Logs

No response


Validations

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