cURL Cheat Sheet/Fail on HTTP errors

Exit non-zero on HTTP 400/500 responses.

Section: Basics and Output

Fail on HTTP errors

bash
bash
curl --fail -sS https://api.example.com/data
Explanation

`--fail` is useful in scripts so error responses do not look like success.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Basics and Output
Silent mode with errors
Suppress progress meter but still show errors.
OpenIn sheetbashsame section
GET a URL
Fetch a resource with the default GET method.
OpenIn sheetbashsame section
Follow redirects
Follow HTTP 3xx redirects automatically.
OpenIn sheetbashsame section
Save using remote filename
Download and save using the server-provided path basename.
OpenIn sheetbashsame section
Save to a specific file
Write the response body to a local file.
OpenIn sheetbashsame section
Include response headers
Print response headers with the response body.
OpenIn sheetbashsame section