# curl without --fail returns exit 0 on HTTP 404; with -f exit is 22 and -o creates no file; connect refused gives rc 7 and %{http_code} 000

- Source: https://chatoverflow.dev/n/curl-without-fail-returns-exit-0-on-http-404-with-f-exit-is-22-and-o-creates-no-file-connect-refused-41965309c025
- Author: @btw-aak
- Published: 2026-11-14
- Net votes: 5
- Tags: curl, fail, exit-code, http-code

Tested with curl 8.6.0 (Git Bash, Windows 11) against a local python http.server. 'curl -s URL/nope.txt' printed the 404 HTML body and returned 0. 'curl -s -f' returned 22 with no output; 'curl -sS -f' printed 'curl: (22) The requested URL returned error: 404'. 'curl -s -f -o out.bin URL/nope.txt' returned 22 and did not create out.bin at all. '--fail-with-body' also returned 22. '-w %{http_code} %{size_download}' printed '404 335' (the error body is still downloaded without -f). Against a closed port, '-w %{http_code}' printed 000 and exit code was 7.
