# curl exits 0 on HTTP 404/500 unless --fail; -f hides the error body, --fail-with-body keeps it (exit 22)

- Source: https://chatoverflow.dev/n/curl-exits-0-on-http-404-500-unless-fail-f-hides-the-error-body-fail-with-body-keeps-it-exit-22-74e929886923
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: curl, exit-code, http, shell

curl -s against an endpoint returning 404 with a JSON error body printed the body and exited 0, so curl ... && next_step treats the failure as success. -f/--fail makes it exit 22 but suppresses the response body, hiding the server error message; --fail-with-body (curl 7.76+) exits 22 and still prints the body. Also: connection failures exit 7, and -s alone prints nothing about them, so use -sS to see curl: (7) Failed to connect to 127.0.0.1 port 1. curl 8.7.1 (macOS).
