<p>It should return HTTP status 500 if the transaction doesn't exist. 404 is just for method-does-not-exist errors. (See <a href="https://github.com/bitcoin/bitcoin/blob/master/src/rpc/protocol.h#L38" rel="nofollow noreferrer">here</a>.) Reading the code, I don't see how error 404 could be returned for a transaction not existing. (I checked the current code and 0.13.)</p>

<p>HTTP status codes are pretty non-specific. You should parse the JSON response if you want something more specific than 'an error happened.' (But it doesn't always return JSON. IIRC, 401 Authorization errors aren't JSON.)</p>

CC BY-SA 3.0
2017-05-18T06:45:29.843Z
This is the problem I'm mentioning, the error response is not json and has even changed across versions: https://github.com/bitcoin/bitcoin/commit/db904db7e6b87fefecde564dea132ff8614726da thus, one cannot distinguish between an error state of the server and the server claiming that the tx doesn't exist. I disagree that 500 should be thrown here, because 5xx errors are "server errors" and it's not a server error, it's just a normal response. See https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#5xx_Server_error , querying about a non-existent transaction is not something "unexpected".
knocte
CC BY-SA 3.0
2017-05-18T06:45:37.830Z
404 doesn't mean "method not found" but simply "not found". Method not found would actually be better mapped to 400 "bad request"
knocte
CC BY-SA 3.0
2017-05-18T16:06:05.353Z
1) [Looks like JSON to me](https://pastebin.com/wnXzDYGX). What do you get? If you want something that _usually_ doesn't change between versions, the JSON error code (the negative number) changes less often than the error message. 2) Hey, I didn't pick the status codes. Just be glad it's not [error 418](https://en.wikipedia.org/wiki/Hyper_Text_Coffee_Pot_Control_Protocol).
Nick ODell
CC BY-SA 3.0
2017-05-18T06:25:28.887Z
2017-05-18T06:25:28.887Z
Nick ODell
<p>As far as I understand, if you supply a made up TxID to the <code>getrawtransaction</code> RPC API, it should return an error code that suggests the record is not found (i.e. 404 HTTP STATUS CODE?). However, in bitcoin-core 0.12.1 and 0.13.1 it's returning 500-Internal Server Error, as if the node had some problem processing the request.</p>

<p>FYI, I have <code>txindex=1</code> enabled in this node, so it's not because of the lack of data. Should this be fixed upstream or is it already fixed? Or is there a better reason for why this is the case?</p>

<bitcoin-core><json-rpc><raw-transaction>
Why getrawtransaction returns an HTTP STATUS CODE 500 for not found transactions?
knocte
# Why getrawtransaction returns an HTTP STATUS CODE 500 for not found transactions?

(Asked by: username_0 on 2017-05-18)

As far as I understand, if you supply a made up TxID to the `getrawtransaction` RPC API, it should return an error code that suggests the record is not found (i.e. 404 HTTP STATUS CODE?). However, in bitcoin-core 0.12.1 and 0.13.1 it's returning 500-Internal Server Error, as if the node had some problem processing the request.

FYI, I have `txindex=1` enabled in this node, so it's not because of the lack of data. Should this be fixed upstream or is it already fixed? Or is there a better reason for why this is the case?

**Tags:** bitcoin-core, json-rpc, raw-transaction


---

## 1 answers

### Answer by username_1 on 2017-05-18. Score: 1

It should return HTTP status 500 if the transaction doesn't exist. 404 is just for method-does-not-exist errors. (See [here](https://github.com/bitcoin/bitcoin/blob/master/src/rpc/protocol.h#L38).) Reading the code, I don't see how error 404 could be returned for a transaction not existing. (I checked the current code and 0.13.)

HTTP status codes are pretty non-specific. You should parse the JSON response if you want something more specific than 'an error happened.' (But it doesn't always return JSON. IIRC, 401 Authorization errors aren't JSON.)

> **Comments:**
> **username_0**: This is the problem I'm mentioning, the error response is not json and has even changed across versions: https://github.com/bitcoin/bitcoin/commit/db904db7e6b87fefecde564dea132ff8614726da thus, one cannot distinguish between an error state of the server and the server claiming that the tx doesn't exist. I disagree that 500 should be thrown here, because 5xx errors are "server errors" and it's not a server error, it's just a normal response. See https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#5xx_Server_error , querying about a non-existent transaction is not something "unexpected".  
> **username_0**: 404 doesn't mean "method not found" but simply "not found". Method not found would actually be better mapped to 400 "bad request"  
> **username_1**: 1) [Looks like JSON to me](https://pastebin.com/wnXzDYGX). What do you get? If you want something that _usually_ doesn't change between versions, the JSON error code (the negative number) changes less often than the error message. 2) Hey, I didn't pick the status codes. Just be glad it's not [error 418](https://en.wikipedia.org/wiki/Hyper_Text_Coffee_Pot_Control_Protocol).  

---

