<p>I ended up implementing a response handler that implements the following heuristic:</p>

<ul>
<li>If status code is 200 and Content-Type header is "application/json" (with or without charset), the response is valid.</li>
<li>If the status code is 200 or 500 (I've observed both) and the Content-Type header is "text/html" (with or without charset), the response is erroneous and the error message may be extracted with the following regular expression: <code>(?s).*&lt;div.*?class="alert alert-error"&gt;.*?&lt;h4&gt;(.*?)&lt;/h4&gt;.*</code>.</li>
<li>Otherwise the response is erroneous but the specific error message cannot be extracted.</li>
</ul>

<p>This seems to work well in practice.</p>

CC BY-SA 3.0
2013-05-25T17:41:14.733Z
2013-05-25T17:41:14.733Z
Tomer Gabel
<p>I've been working on a project involving use of the various Blockchain.info APIs (specifically  the <a href="https://blockchain.info/api/blockchain_api" rel="nofollow">Blockchain Data API</a>), and am wondering if anyone has tips regarding error handling: the API documentation says nothing about how errors are handled, and my experiments seem to indicate that errors are returned with HTTP status 200 and a strictly HTML response.</p>

<p>Has anyone implemented a client for this API and can shed some light on whether this is the "usual" state of affairs or a bug? Any additional tips would be greatly appreciated.</p>

<blockchain.info><api>
Blockchain.info API error handling
Tomer Gabel
# Blockchain.info API error handling

(Asked by: username_0 on 2013-05-19)

I've been working on a project involving use of the various Blockchain.info APIs (specifically the [Blockchain Data API](https://blockchain.info/api/blockchain_api)), and am wondering if anyone has tips regarding error handling: the API documentation says nothing about how errors are handled, and my experiments seem to indicate that errors are returned with HTTP status 200 and a strictly HTML response.

Has anyone implemented a client for this API and can shed some light on whether this is the "usual" state of affairs or a bug? Any additional tips would be greatly appreciated.

**Tags:** blockchain.info, api


---

## 1 answers

### Answer by username_0 on 2013-05-25. Score: 1

I ended up implementing a response handler that implements the following heuristic:

* If status code is 200 and Content-Type header is "application/json" (with or without charset), the response is valid.
* If the status code is 200 or 500 (I've observed both) and the Content-Type header is "text/html" (with or without charset), the response is erroneous and the error message may be extracted with the following regular expression: `(?s).*.*?

  #### (.*?)

  .*`.
* Otherwise the response is erroneous but the specific error message cannot be extracted.

This seems to work well in practice.


---

