exit when curl fails

I wanted curl to fail when it thorugh a request error above 400. but it was’nt. $? was not giving me a error code above 0. so the only way I can tell if a error was thrown is if I combed the string for a particular pattern. but then I found this option for the curl command

--fail

but when it fails it does’nt tell you why. It just silently exits, then I found this

--fail-with-body

which is exactly what I want but this option does not exists on the current version of curl I have installed on my system.

curl: option –fail-with-body: is unknown

is this article, he describes that the version 7.76 this option was added

So I came up with another solution

trap 'command=$BASH_COMMAND' ERR

I obtained the last command using “trap” then removed the –fail flag and ran it again using eval

Leave a Reply

Your email address will not be published.