TransWikia.com

HTTP status codes for failing requests

Tezos Asked by Ivan Gromakovskii on August 20, 2021

There is a list of all possible RPC errors at this page: http://tezos.gitlab.io/api/errors.html
According to my experiments, these errors are returned differently. I found at least two different ways to return an error in response to run_operation:

  1. Return 200 OK status code, put a list of errors into the operation_result object for the errors key.
  2. Return 500 status code with body containing a list of errors and no other data.

Example of 1:

{"contents":[{"kind":"transaction","source":"tz1V8fDHpHzN8RrZqiYCHaJM9EocsYZch5Cy","fee":"0","counter":"3","gas_limit":"1040000","storage_limit":"60000","amount":"0","destination":"KT1GExrhg5QdAMuzhKv3KbrXDQUDBMAeduvk","metadata":{"balance_updates":[],"operation_result":{"status":"failed","errors":[{"kind":"temporary","id":"proto.006-PsCARTHA.michelson_v1.runtime_error","contract_handle":"KT1GExrhg5QdAMuzhKv3KbrXDQUDBMAeduvk","contract_code":[{"prim":"storage","args":[{"prim":"unit"}]},{"prim":"parameter","args":[{"prim":"unit"}]},{"prim":"code","args":[[{"prim":"CAR"},{"prim":"FAILWITH"}]]}]},{"kind":"temporary","id":"proto.006-PsCARTHA.michelson_v1.script_rejected","location":8,"with":{"prim":"Unit"}}]}}}]}

Example of 2:

[{"kind":"temporary","id":"proto.006-PsCARTHA.contract.counter_in_the_future","contract":"tz1V8fDHpHzN8RrZqiYCHaJM9EocsYZch5Cy","expected":"2","found":"3"}]

I have two questions:

  1. How does tezos-node decide which status code to use? Is it documented anywhere? My hypothesis was that it depends on the kind, but it’s not the case because in my example all errors have "temporary" kind. My another hypothesis is that it depends on the number of reported errors: if there is only one error, 500 is returned, otherwise 200. But then why does 500 response have a list in its body?
  2. What’s the point of returning 500 status code in these cases? It means "Internal server error" which I treat as "something is wrong on the server". But if I for example try to make an operation with a wrong counter, it doesn’t mean that anything is wrong with the server. So I am confused.

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP