resgateio/resgate

Add system.invalidQuery error response

Closed this issue · 1 comments

Issue

The RES Protocol lacks any proper way to respond to requests where the provided query is invalid.

Service developers currently has to to use workarounds which includes replying with a custom error, or improperly use the existing system.invalidParams error code.

Solution

This can be solved by introducing a new pre-defined error:

Code Message Meaning
system.invalidQuery Invalid query The query is malformed or contains invalid values

The new error code would be similar to system.invalidParams, but differ in regards that system.invalidParams refers to the params of a call/auth method requests, whereas system.invalidQuery would refer to the query in any type of request.

Notes

HTTP status code

For HTTP requests, the system.invalidQuery error code would translate to a 400 Bad Request by Resgate. While using 422 Unprocessable Entity from the WebDAV extension might be more appropriate, the 400 status code is consistent with the status code Resgate uses for system.invalidParams error codes.

When to use

The system.invalidQuery should be sent when the query string cannot be parsed due to malformed content. It should also be sent if the parsed query contains values that are not allowed (eg. limit=1000 when limit must be <= 50), but the service may choose not to send an error, but to use a default value (eg. limit=50) in the normalized query. However, this behavior would be unclear to the consumer of the API, and is not recommended.

It error should not be sent if the query contains keys that are not used by the service (eg. limit=20&foo=bar). It is recommended that the service simply ignores the key and excludes it from the normalized query (eg. limit=20).

Resolved in #120