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

Show errors in a consistent way #123

Open
cstenglein opened this issue Jun 19, 2022 · 5 comments
Open

Show errors in a consistent way #123

cstenglein opened this issue Jun 19, 2022 · 5 comments
Labels
enhancement New feature or request good first issue Good for newcomers v0.6.0-beta
Milestone

Comments

@cstenglein
Copy link
Collaborator

Currently, the error comes in weird formats, depending on the endpoint.

Do not send an error array. but only one error at a time.

@fusion44
Copy link
Owner

Can you give some examples? What is a not weird format?

Not sure I can do anything about the error array response... that's a FastAPI thing. Will check.

@fusion44 fusion44 added the enhancement New feature or request label Jun 20, 2022
@cstenglein
Copy link
Collaborator Author

There are currently 3 ways a error is displayed: just in detail, as detail.msg, and detail[X].msg (X is an integer).

As a user of blitz_api, I would like to have consistent error messages, either in detail or in detail.msg. Multiple errors are not really necessary IMO, since you could just show the "next" error.

Scenario 1

When I call system/login with a wrong password, I get the following response:

{
  "detail": [
    {
      "loc": [
        "body",
        "password"
      ],
      "msg": "ensure this value has at least 8 characters",
      "type": "value_error.any_str.min_length",
      "ctx": {
        "limit_value": 8
      }
    }
  ]
}

=> So I access detail.msg.

When I get an unauthenticated error, e.g. by calling system/change-password, I get the following response:

{
  "detail": "Not authenticated"
}

=> So I need to access just detail.

Scenario 2

When I call system/change-password and I enter the wrong old_password:

{
  "detail": "old password format invalid"
}

=> So I need to access just detail. again

When I call /lightning/new-address with the request body

{
  "type": "p2w2"
}

I get the details as an array:

{
  "detail": [
    {
      "loc": [
        "body",
        "type"
      ],
      "msg": "value is not a valid enumeration member; permitted: 'p2wkh', 'np2wkh'",
      "type": "type_error.enum",
      "ctx": {
        "enum_values": [
          "p2wkh",
          "np2wkh"
        ]
      }
    }
  ]
}

=> So there I need to access detail[0].msg

@fusion44
Copy link
Owner

That there are multiple errors returned is a Fastapi thing. If you call an endpoint with multiple wrong query args then you'll get an error array with an error message for each. We can't change this without forking FastAPI.

What we can do is always return an array where the first element is the actual error message. Need to look into this more.

@fusion44
Copy link
Owner

fusion44 commented Apr 8, 2024

TIL: https://www.rfc-editor.org/rfc/rfc9457.html

This standard describes error handling for apis.

Here's more some information:
https://blog.frankel.ch/problem-details-http-apis/

Might be a good idea to implement this standard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers v0.6.0-beta
Projects
None yet
Development

No branches or pull requests

2 participants