curl -f / --fail: Fail the Step on HTTP Errors
By default curl exits 0 even on a 500, which silently passes broken steps. -f changes that.
In a pipeline you almost always want a bad HTTP status to fail the job. -f / --fail is the smallest change that gets you there.
What it does
With -f / --fail, curl returns exit code 22 for HTTP responses 400 and above instead of exit 0. The response body is not printed on error. Without it, curl considers any completed transfer a success regardless of status code, so a 404 or 500 still exits 0.
Common usage
curl -f https://api.example.com/health
curl -fsS https://api.example.com/health # fail + silent + show errors
curl --fail -X POST https://api.example.com/deployFlags
| Flag | What it does |
|---|---|
| -f / --fail | Exit 22 on HTTP >= 400; suppress the error body |
| --fail-with-body | Exit non-zero on >= 400 but still print the body (curl 7.76+) |
| --fail-early | Fail on the first error across multiple URLs |
| -sS | Pair with --fail: silent progress, but still show errors |
In CI
A step that runs curl without -f will pass even when the server returns 500, hiding outages. Use -fsS for API calls so a bad status sets a non-zero exit and the step fails. Use --fail-with-body when you need the error JSON for debugging (it needs curl 7.76 or newer).
Common errors in CI
curl: (22) The requested URL returned error: 404 means the request reached the server and got a 4xx/5xx; this is the intended failure from -f. If you also need the body, switch to --fail-with-body. Note the exact wording varies by curl version.