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

Question: defining strict error schemas #392

Open
qweeze opened this issue Nov 20, 2024 · 1 comment
Open

Question: defining strict error schemas #392

qweeze opened this issue Nov 20, 2024 · 1 comment

Comments

@qweeze
Copy link

qweeze commented Nov 20, 2024

We use errors[].data field to pass detailed errors to client, like so:

{
    "jsonrpc": "2.0",
    "error": {
        "code": 6000,
        "message": "Invalid parameters",
        "data": {
            "errors": [
                {
                    "code":"wrong_code",
                    "path": "sms_code",
                    "message": "Verification code mismatch"
                },
                {
                    "code":"wrong_payee_id",
                    "path": "payments[2].payee",
                    "message": "Invalid payee ID"
                }
            ]
        }
    },
    "id": 42
}

We'd like to be able to specify JSON schemas for these (inner) errors, without violating the OpenRPC spec or breaking backwards compatibility. We've come up with the following approach:

  • put the JSON schemas of inner errors in the errors[].data attribute of an OpenRPC schema
  • add a custom global-scoped flag, i.e. x-error-data-schema: bool which indicates should the data property of errors be treated as a schema or not. If the flag is set, all the related tools (validators, code generators, documentation viewers) should assume that error responses' data attribute is constrained with these schemas and act accordingly.

Alternatively, the spec itself could probably be updated to support defining specific schemas for errors. I might be wrong but it feels like a nice-to-have feature that could come in handy not only for our use case. As for implementation, adding a separate dedicated attribute like errors[].data-schema should suffice.

To sum up, my questions are:

  1. Is our approach with adding x-error-data-schema a legit and intended/idiomatic way of expanding the spec?
  2. Should we propose a spec update?
Copy link

Welcome to OpenRPC! Thank you for taking the time to create an issue. Please review the guidelines

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