Concordium / concordium-rosetta

A server implementing the Rosetta API for the Concordium blockchain.
Mozilla Public License 2.0
5 stars 1 forks source link

Respond with appropriate HTTP code on error #14

Closed bisgardo closed 2 years ago

bisgardo commented 2 years ago

Description

The server currently responds with status code 200 on all requests, even if they fail.

Steps to Reproduce

Trigger any error, like query a block by an invalid hash.

Expected Result

The response is not a 200.

Actual Result

The response is a 200. The body contents of the response is correct.

Example:

$ curl -v -Hcontent-type:application/json localhost:8080/block -d '{"network_identifier":{"blockchain":"concordium","network":"testnet"}, "block_identifier":{"hash":"123"}}' | jq .
*   Trying ::1:8080...
* connect to ::1 port 8080 failed: Connection refused
*   Trying 127.0.0.1:8080...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> POST /block HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.74.0
> Accept: */*
> content-type:application/json
> Content-Length: 105
> 
} [105 bytes data]
* upload completely sent off: 105 out of 105 bytes
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< content-type: application/json
< content-length: 245
< date: Tue, 03 May 2022 13:21:34 GMT
< 
{ [245 bytes data]
* Connection #0 to host localhost left intact
{
  "code": 1200,
  "message": "invalid input: invalid value or identifier",
  "description": "The provided value or identifier is incorrectly typed or formatted.",
  "retriable": false,
  "details": {
    "message": "invalid hash value '123'",
    "name": "block identifier"
  }
}

Versions