curl/docs/cmdline-opts/fail.md
2024-06-05 11:00:46 +02:00

1.1 KiB

c SPDX-License-Identifier Long Short Protocols Help Category Mutexed Added Multi See-also Example
Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. curl fail f HTTP Fail fast with no output on HTTP errors important http fail-with-body 4.0 boolean
fail-with-body
fail-early
--fail $URL

--fail

Fail with error code 22 and with no response body output at all for HTTP transfers returning HTTP response codes at 400 or greater.

In normal cases when an HTTP server fails to deliver a document, it returns a body of text stating so (which often also describes why and more) and a 4xx HTTP response code. This command line option prevents curl from outputting that data and instead returns error 22 early. By default, curl does not consider HTTP response codes to indicate failure.

To get both the error code and also save the content, use --fail-with-body instead.

This method is not fail-safe and there are occasions where non-successful response codes slip through, especially when authentication is involved (response codes 401 and 407).