mirror of
https://github.com/httpie/cli.git
synced 2025-06-21 01:57:42 +02:00
Improved --check-status + HTTP error + stdout redirect warning.
This commit is contained in:
parent
53caf6ae72
commit
f2d59ba6bd
@ -60,9 +60,10 @@ def main(args=sys.argv[1:], env=Environment()):
|
|||||||
if env.config.default_options:
|
if env.config.default_options:
|
||||||
args = env.config.default_options + args
|
args = env.config.default_options + args
|
||||||
|
|
||||||
def error(msg, *args):
|
def error(msg, *args, **kwargs):
|
||||||
msg = msg % args
|
msg = msg % args
|
||||||
env.stderr.write('\nhttp: error: %s\n' % msg)
|
level = kwargs.get('level', 'error')
|
||||||
|
env.stderr.write('http: %s: %s\n' % (level, msg))
|
||||||
|
|
||||||
debug = '--debug' in args
|
debug = '--debug' in args
|
||||||
traceback = debug or '--traceback' in args
|
traceback = debug or '--traceback' in args
|
||||||
@ -81,8 +82,12 @@ def main(args=sys.argv[1:], env=Environment()):
|
|||||||
if args.check_status:
|
if args.check_status:
|
||||||
exit_status_code = get_exist_status_code(response.status_code,
|
exit_status_code = get_exist_status_code(response.status_code,
|
||||||
args.follow)
|
args.follow)
|
||||||
if exit_status_code != ExitStatus.OK and not env.stdout_isatty:
|
|
||||||
error('%s %s', response.raw.status, response.raw.reason)
|
if not env.stdout_isatty and exit_status_code != ExitStatus.OK:
|
||||||
|
error('HTTP %s %s',
|
||||||
|
response.raw.status,
|
||||||
|
response.raw.reason,
|
||||||
|
level='warning')
|
||||||
|
|
||||||
write_kwargs = {
|
write_kwargs = {
|
||||||
'stream': build_output_stream(
|
'stream': build_output_stream(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user