utility-option

curl --fail-with-body

Available since curl 7.76.0; HTTP errors can return exit 22 while retaining body bytes. Inspect expected HTTP status separately; not a schema validator. Local mock server required.

Formal Syntax & Structure

bash syntaxbash
curl --fail-with-body -o FILE -w FORMAT URL

Return Value

exit status

Available since curl 7.76.0; HTTP errors can return exit 22 while retaining body bytes. Inspect expected HTTP status separately; not a schema validator. Local mock server required.

Working Example

Example Snippetbash
[[ ${BM_API_BASE-} =~ ^http://127\.0\.0\.1:[0-9]{1,5}$ ]] || exit 2code=$(curl -q --noproxy "*" --proto "=http" -sS --connect-timeout 1 --max-time 2 --fail-with-body -o body.json -w '%{http_code}' "$BM_API_BASE/missing" 2>diagnostic.txt)rc=$?printf 'curl=%s http=%s\n' "$rc" "$code"cat body.json[[ $rc == 22 && -s diagnostic.txt ]]
Bash Reference