GNURLOPT_FAILONERROR(3)

πŸ“¦ version 7.72.0, in nixos 26.05, nixpkgs unstable

πŸ’… GNURLOPT_FAILONERROR(3) πŸ’…

okay so this page is from the curl_easy_setopt options manual, and it's all about making HTTP error codes actually count as errors instead of just being ignored like they're not even in the group chat. bestie, let's get into it. 🫢


✨ NAME ✨

CURLOPT_FAILONERROR β€” request failure on HTTP response >= 400. literally that's the whole vibe check. πŸ’–


✨ SYNOPSIS ✨

#include <gnurl/curl.h>

CURLcode curl_easy_setopt(CURL *handle, CURLOPT_FAILONERROR, long fail);

✨ DESCRIPTION ✨

A long parameter set to 1 tells the library to fail the request if the HTTP code returned is equal to or larger than 400. the default action would be to return the page normally, ignoring that code. like, no cap, it just pretends everything is fine and hands you the page anyway. πŸ™ˆ

This method is not fail-safe, and there are occasions where non-successful response codes will slip through β€” especially when authentication is involved (response codes 401 and 407). so highkey watch out for those. πŸ’€

You might get some amounts of headers transferred before this situation is detected, like when a "100-continue" is received as a response to a POST/PUT and a 401 or 407 is received immediately afterwards. it's giving "almost caught it in time." 😭

When this option is used and an error is detected, it will cause the connection to get closed and CURLE_HTTP_RETURNED_ERROR is returned. periodt. πŸ”₯


✨ DEFAULT ✨

0, do not fail on error. so by default it's in chill mode. πŸ’…


✨ PROTOCOLS ✨

HTTP. that's the one. 🌸


✨ EXAMPLE ✨

CURL *curl = curl_easy_init();
if(curl) {
  CURLcode ret;
  curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
  curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1L);
  ret = curl_easy_perform(curl);
  if(ret == CURLE_HTTP_RETURNED_ERROR) {
    /* an HTTP response error problem */
  }
}

look at that little icon living its best life. CURLE_HTTP_RETURNED_ERROR is the main character here. πŸ‘‘


✨ AVAILABILITY ✨

Along with HTTP. yep, it came in with HTTP. πŸ’–


✨ RETURN VALUE ✨

Returns CURLE_OK if HTTP is enabled, and CURLE_UNKNOWN_OPTION if not. simple as that, bestie. ✨


✨ SEE ALSO ✨

go read those too, iykyk. πŸ¦‹


made with πŸ’– from libcurl 7.37.0, stamped 17 Jun 2014. bye bestie, slay your HTTP errors responsibly. πŸŽ€

πŸ“¦ where this page comes from