pyeve / eve

REST API framework designed for human beings
https://python-eve.org
Other
6.68k stars 747 forks source link

Can I add detailed error message and unique error identifier to error response? #1448

Open itsjef opened 3 years ago

itsjef commented 3 years ago

I am developing a dictionary application. On the backend side, there are certain validation rules for a dictionary entry. This is the error response when one of them is violated:

{
    "_state": "ERR",
    "_issues": {
        "pronunciation": "must be of ja_pronunciation type"
    },
    "_error": {
        "code": 422,
        "message": "Insertion failure: 1 document(s) contain(s) error(s)"
    }
}

However, when the frontend client consumes this response, the error message is not user-friendly enough to display directly on the web page. Additionally, to support i18n, it must also provide the message in another language (e.g: Japanese).

It would be nice if I can provide 2 new attributes besides the default message:

The response would look like this:

{
    "_state": "ERR",
    "_issues": {
        "pronunciation": {
            "error": "InvalidPronunciationError",
            "message": "must be of ja_pronunciation type",
            "detail": "Pronunciation must be standard Hiragana or Katanata characters"
        }
    },
    "_error": {
        "code": 422,
        "message": "Insertion failure: 1 document(s) contain(s) error(s)"
    }
}

Environment

@nicolaiarocci Thank you for reading and please tell me what you think.

itsjef commented 3 years ago

Looks like I can derive from https://github.com/pyeve/cerberus/issues/174 :thinking:

Ziul commented 3 years ago

I came here looking similar to the Mongo Schema Validation, where I could write in a field description the requirements of the field. Unfortunately looks like Cerberror is the closest solution to what I want. But this is too deep inside Eve to just "replace".

stale[bot] commented 2 years ago

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

itsjef commented 2 years ago

It is still relevant.