Skip to content

Complex Errors #40

@theduke

Description

@theduke

As I can see, right now, only a simple String error for the message field is supported.

I often need more complex errors with additional data, like this for example:

"errors": [
  {
    "message": "Validation failed", 
    "code": "validation_err",
    "data": {
      "username": {"code": "min_length", "message": "must be at least 5 characters long", "meta": {"min": 5, "max": 15}}
    }
  }
]

Do you see a way to implement this?

It would require changing the type of FieldResult.

As an idea:

pub enum FieldError {
  Simple(String),
  Custom(String, json_value::Value),
}

type FieldResult<T> = Result<T, FieldError>;

The problem is the type of the extra data.
It would require either having FieldError be generic over a type that implements Serialize (for serde) or tying it to a value type like serde_value or json_value::Value.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementImprovement of existing features or bugfix

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions