tarantool / nginx_upstream_module

Tarantool NginX upstream module (REST, JSON API, websockets, load balancing)
Other
174 stars 18 forks source link

Common error handling problems #58

Closed Sulverus closed 8 years ago

Sulverus commented 8 years ago

Configuration

if ( $request_method = GET ) {
    tnt_method "read";
}
if ( $request_method = PUT ) {
    tnt_method "insert";
}
if ( $request_method = POST ) {
    tnt_method "update";
}
if ( $request_method = DELETE ) {
    tnt_method "delete";
}
tnt_http_rest_methods get delete;
tnt_http_methods all;
tnt_multireturn_skip_count 2;
tnt_pure_result on;
tnt_pass_http_request on parse_args;
tnt_pass tnt;

Need to have Bad Request response for put/post requests without params field. Must be fixed in nginx side (for example we can insert empty params arg)

{
    "id": 0,
    "method": "insert"
}
{
    "id": 0,
    "error": {
        "message": "Missing mandatory field 'tuple' in request",
        "code": -32837
    }
}

Need to have Bad Request response for put requests without body

{
    "id": 0,
    "error": {
        "message": "Procedure '' is not defined",
        "code": -32601
    }
}

Need discuss response format for invalid json from client

{ method":"update","params":[{"uid":79030000005,"date":201607251313,"text":"201607251313"}] }
{
  "error": {
    "code": -32700,
    "message": "lexical error: invalid char in json text."
  }
}
{ "method": "insert", "params": [{  "p2":  }] }
{
  "error": {
    "code": -32700,
    "message": "parse error: unallowed token at this point in JSON text"
  }
}
dedok commented 8 years ago

The first one, if you use the body to transfer data, the 'params' is required by protocol (see readme with protocol description).

The second one,

{ "id": 0, "error": { "message": "Procedure '' is not defined", "code": -32601 } }

How did you got this? Could you provide your request?

-- Need discuss response format for invalid json from client Could you create another issue for that? This is not a bug, this is a feature request.

Sulverus commented 8 years ago

Conclusion:

  1. POST/PUT/DELETE without body -> replace with {"params": []}
  2. POST/PUT/DELETE without params -> replace with {"params":[]}
Sulverus commented 8 years ago

rejected second case

  1. POST/PUT/DELETE without params -> replace with {"params":[]}