Issue
I am calling a service via curl and in case of success I want to get the result in a variable. So I do this call:
result=$(curl -s $URL)
For the success case this works well. In case of an error I get just null in the variable.
In case of error the service throws some http code like 400 and returns some details in the response.
How can I also evaluate the error and fetch the error response?
Solution
Stderror to file:
command 2> file
Stderror to stdout:
command > file 2>&1
Try these flags with curl for stderror:
--fail --silent --show-error
Answered By - KafKafOwn Answer Checked By - Mary Flores (WPSolving Volunteer)