Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
itsjef opened this issue Mar 31, 2021 · 4 comments

Comments

@itsjef
Copy link
Contributor

itsjef commented Mar 31, 2021

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:

  • detail: A human-readable, lengthier explanation of the error, suitable for direct display.
  • error: An unique identifier to the error in the response. It could be the class name of an exception. The client can also map this identifier to any custom messages instead of using the detail string above.

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

  • Python version: 3.8.5
  • Eve version: 1.1.5

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

@itsjef
Copy link
Contributor Author

itsjef commented Apr 1, 2021

Looks like I can derive from pyeve/cerberus#174 🤔

@Ziul
Copy link

Ziul commented Aug 25, 2021

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
Copy link

stale bot commented Apr 16, 2022

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.

@stale stale bot added the stale label Apr 16, 2022
@itsjef
Copy link
Contributor Author

itsjef commented Apr 18, 2022

It is still relevant.

@stale stale bot removed the stale label Apr 18, 2022
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

No branches or pull requests

2 participants