HTTP Interface

## Valid JSON/XML response on exception during HTTP streaming[​](#valid-output-on-exception-http-streaming "Direct link to Valid JSON/XML response on exception during HTTP streaming")

While query execution occurs over HTTP an exception can happen when part of the data has already been sent. Usually an exception is sent to the client in plain text.
Even if some specific data format was used to output data and the output may become invalid in terms of specified data format.
To prevent it, you can use setting [`http_write_exception_in_output_format`](/docs/operations/settings/settings#http_write_exception_in_output_format) (disabled by default) that will tell ClickHouse to write an exception in specified format (currently supported for XML and JSON\* formats).

Examples:

```
$ curl 'http://localhost:8123/?query=SELECT+number,+throwIf(number>3)+from+system.numbers+format+JSON+settings+max_block_size=1&http_write_exception_in_output_format=1'
{
    "meta":
    [
        {
            "name": "number",
            "type": "UInt64"
        },
        {
            "name": "throwIf(greater(number, 2))",
            "type": "UInt8"
        }
    ],

    "data":
    [
        {
            "number": "0",
            "throwIf(greater(number, 2))": 0
        },
        {
            "number": "1",
            "throwIf(greater(number, 2))": 0
        },
        {
            "number": "2",
            "throwIf(greater(number, 2))": 0
        }
    ],

    "rows": 3,

    "exception": "Code: 395. DB::Exception: Value passed to 'throwIf' function is non-zero: while executing 'FUNCTION throwIf(greater(number, 2) :: 2) -> throwIf(greater(number, 2)) UInt8 : 1'. (FUNCTION_THROW_IF_VALUE_IS_NON_ZERO) (version 23.8.1.1)"
}
```

```
$ curl 'http://localhost:8123/?query=SELECT+number,+throwIf(number>2)+from+system.numbers+format+XML+settings+max_block_size=1&http_write_exception_in_output_format=1'
<?xml version='1.0' encoding='UTF-8' ?>
<result>
    <meta>
        <columns>
            <column>
                <name>number</name>
                <type>UInt64</type>
            </column>
            <column>
                <name>throwIf(greater(number, 2))</name>
                <type>UInt8</type>
            </column>
        </columns>
    </meta>
    <data>
        <row>
            <number>0</number>
            <field>0</field>
        </row>
        <row>
            <number>1</number>
            <field>0</field>
        </row>
        <row>
            <number>2</number>
            <field>0</field>
        </row>
    </data>
    <rows>3</rows>
    <exception>Code: 395. DB::Exception: Value passed to 'throwIf' function is non-zero: while executing 'FUNCTION throwIf(greater(number, 2) :: 2) -> throwIf(greater(number, 2)) UInt8 : 1'. (FUNCTION_THROW_IF_VALUE_IS_NON_ZERO) (version 23.8.1.1)</exception>
</result>
```

- [Prerequisites](#prerequisites)- [Overview](#overview)- [Web user interface](#web-ui)- [Querying over HTTP/HTTPS](#querying)- [Insert queries over HTTP/HTTPS](#insert-queries)
          - [Examples](#examples)- [Compression](#compression)- [Examples](#examples-compression)- [Default database](#default-database)- [Authentication](#authentication)- [Using ClickHouse sessions in the HTTP protocol](#using-clickhouse-sessions-in-the-http-protocol)- [Response buffering](#response-buffering)- [Setting a role with query parameters](#setting-role-with-query-parameters)- [HTTP response codes caveats](#http_response_codes_caveats)- [Queries with parameters](#cli-queries-with-parameters)
                            - [Example](#example-3)- [Tabs in URL Parameters](#tabs-in-url-parameters)- [Predefined HTTP Interface](#predefined_http_interface)
                              - [predefined\_query\_handler](#predefined_query_handler)- [dynamic\_query\_handler](#dynamic_query_handler)- [static](#static)- [redirect](#redirect)- [HTTP response headers](#http-response-headers)- [Valid JSON/XML response on exception during HTTP streaming](#valid-output-on-exception-http-streaming)

Was this page helpful?