1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: CURLOPT_FAILONERROR
5Section: 3
6Source: libcurl
7See-also:
8  - CURLINFO_RESPONSE_CODE (3)
9  - CURLOPT_HTTP200ALIASES (3)
10  - CURLOPT_KEEP_SENDING_ON_ERROR (3)
11Protocol:
12  - HTTP
13---
14
15# NAME
16
17CURLOPT_FAILONERROR - request failure on HTTP response \>= 400
18
19# SYNOPSIS
20
21~~~c
22#include <curl/curl.h>
23
24CURLcode curl_easy_setopt(CURL *handle, CURLOPT_FAILONERROR, long fail);
25~~~
26
27# DESCRIPTION
28
29A long parameter set to 1 tells the library to fail the request if the HTTP
30code returned is equal to or larger than 400. The default action would be to
31return the page normally, ignoring that code.
32
33This method is not fail-safe and there are occasions where non-successful
34response codes slip through, especially when authentication is involved
35(response codes 401 and 407).
36
37You might get some amounts of headers transferred before this situation is
38detected, like when a "100-continue" is received as a response to a POST/PUT
39and a 401 or 407 is received immediately afterwards.
40
41When this option is used and an error is detected, it causes the connection to
42get closed and *CURLE_HTTP_RETURNED_ERROR* is returned.
43
44# DEFAULT
45
460, do not fail on error
47
48# EXAMPLE
49
50~~~c
51int main(void)
52{
53  CURL *curl = curl_easy_init();
54  if(curl) {
55    CURLcode ret;
56    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
57    curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1L);
58    ret = curl_easy_perform(curl);
59    if(ret == CURLE_HTTP_RETURNED_ERROR) {
60      /* an HTTP response error problem */
61    }
62  }
63}
64~~~
65
66# AVAILABILITY
67
68Along with HTTP.
69
70# RETURN VALUE
71
72Returns CURLE_OK if HTTP is enabled, and CURLE_UNKNOWN_OPTION if not.
73