curl / Mailing Lists / curl-users / Single Mail
Buy commercial curl support. We help you work out your issues, debug your libcurl applications, use the API, port to new platforms, add new features and more. With a team lead by the curl founder Daniel himself.

Re: [IDEA] --write-out print body on http error code

From: Daniel Stenberg via curl-users <curl-users_at_lists.haxx.se>
Date: Sat, 27 Jul 2024 23:33:59 +0200 (CEST)

On Wed, 24 Jul 2024, Bastian Jesuiter wrote:

> --Fail-with-body will also print the error into the file, but not display it
> in stdout if --out-file (-o) is specified. So the idea is to basically only
> write into file if status code is okay (or similar ) but error into stdout
> when there is one. (So that it may potentially be included into logs)

Saving to a file or stderr depending on the HTTP response code seems like a
very specific use case to me. A little too specific for my taste.

It can probably be accomplished with a 4-line shell script wrapper:

curl --fail-with-body -o save http://example.com
if test "$?" -eq "22"; then
   cat save >&2
   rm save
fi

-- 
  / daniel.haxx.se
  | Commercial curl support up to 24x7 is available!
  | Private help, bug fixes, support, ports, new features
  | https://curl.se/support.html
-- 
Unsubscribe: https://lists.haxx.se/mailman/listinfo/curl-users
Etiquette:   https://curl.se/mail/etiquette.html
Received on 2024-07-27