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

Report errors as JSON #117

Open
mlms13 opened this issue Mar 14, 2023 · 1 comment
Open

Report errors as JSON #117

mlms13 opened this issue Mar 14, 2023 · 1 comment

Comments

@mlms13
Copy link
Owner

mlms13 commented Mar 14, 2023

One common use case for bs-decode is a webserver that decodes the payload of a request. In this case, it would be desirable to send back a 400 response with a response that includes structured errors that are related to the structure of the request.

Something like:

{
  "first_name": {
    "error": "MissingField",
    "description": "Field \"first_name\" is required but was not present"
  },
  "order_ids": [
    {
      "position": 3,
      "error": "InvalidValue",
      "description": "Expected number but found \"3\""
    }
  ]
}

Not sure what the exact structure should be, but it should be something predictable and easy to describe, so that your webserver can document the errors it will return and clients can theoretically do something useful with that data structure.

We already have examples of converting the structured ParseError type to a string in a way that preserves some of the nesting structure, so I think this should be pretty doable.

@mlms13
Copy link
Owner Author

mlms13 commented Mar 14, 2023

In looking at that example, I think it's important that we use the "error" field consistently so that it can be a discriminator to reconstruct the original error data. Specifically, looking at "order_ids" in that example, there's not enough information to expect the value to be an array.

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

1 participant