Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output errors reason when a request is failing with quiet option #1026

Closed
soullivaneuh opened this issue Jan 27, 2021 · 4 comments
Closed

Output errors reason when a request is failing with quiet option #1026

soullivaneuh opened this issue Jan 27, 2021 · 4 comments
Labels
enhancement New feature or enhancement

Comments

@soullivaneuh
Copy link

I use HTTPie on a script to convert images:

http --quiet --form --download --output "${png_path}" POST https://imagine.company.com/convert \
	stripmeta==true \
	lossless==true \
	type==png \
	background==white \
	file@"${svg_path}"

It works, but when it fail I don't have any information because of the --quiet option:

bash build.sh
HTTPie version: 2.3.0
assets/fa-pro/png/brands/500px.png
make: *** [Makefile:4: build] Error 5

On that case, I have a Bad Gateway error (504).

If I remove it, I have the information but also when it success (200).

It would be great to have the possibility to quiet the output except if it's a request error.

@Almad
Copy link

Almad commented Jan 27, 2021

So something like --quiet-on-success?

@jkbrzt
Copy link
Member

jkbrzt commented Jan 28, 2021

@soullivaneuh You’re working on what looks like a scripted workflow. So you likely want to interrupt the flow if the request fails. For that, it’s better to rely on the exit status code than on the textual output.

You can use --check-status, to instruct HTTPie to check the response status and exit with a non-zero code if there has been a problem (see https://httpie.io/docs#scripting for more details):

if http --quiet --check-status httpbin.org/status/504 ; then
    echo "OK"
else 
    echo "ERROR: $?"
    exit 1
fi
# => ERROR: 5

To your question: --quiet is designed to suppress all output except for errors. That’s how CLI tools typically implement it. What we’re missing, though, is an error message for error responses (but only with --check-status):

When you apply --check-status and the response indicates an error, then we correctly exit with a non-zero code, but we should also write an error message to stderr to play well with --quiet.

@jkbrzt
Copy link
Member

jkbrzt commented Feb 6, 2021

HTTPie 2.4.0 with this change has just been released 🥧

@jkbrzt jkbrzt closed this as completed Feb 6, 2021
@soullivaneuh
Copy link
Author

Wow, just opened an issue from 10 days and I got a new release with clear indications about how to solve my need.

Well done and thanks! I'll test this as soon as possible.

@jkbrzt jkbrzt added the enhancement New feature or enhancement label Feb 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or enhancement
Projects
None yet
Development

No branches or pull requests

3 participants