xh --check-status: Exit Codes for HTTP Status
xh --check-status exits non-zero on a 4xx or 5xx response, matching HTTPie's behavior.
Like HTTPie, xh exits 0 by default even on a 500 because the request completed. --check-status makes the exit code reflect the response status so a bad endpoint fails the step.
What it does
--check-status sets xh's exit code from the response: 0 for 2xx, 3 for an unfollowed 3xx, 4 for 4xx, and 5 for 5xx. This gives you a CI gate straight from the client, with no need to parse the status out of the output.
Common usage
xh --check-status GET example.com/health
xh --check-status --follow GET example.com/
# quiet gate: suppress the body, keep the exit code
xh --check-status --quiet GET :8080/readyOptions
| Exit code | Meaning |
|---|---|
| 0 | 2xx success |
| 3 | Unfollowed 3xx redirect |
| 4 | 4xx client error |
| 5 | 5xx server error |
In CI
Add --follow alongside --check-status when the endpoint issues redirects, otherwise a 3xx yields exit code 3 and fails a step that was actually healthy. Use --quiet for a pure exit-code health gate.
Common errors in CI
A step exiting 3 means the endpoint redirected and you did not follow it; add --follow. If --check-status never fails, confirm the flag is present, since without it xh returns 0 regardless of status. Connection-level failures exit non-zero on their own with a connect error message, independent of --check-status.