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