From f2d59ba6bd1d21f8f79c11c43c8acaa7e2f8c453 Mon Sep 17 00:00:00 2001 From: Jakub Roztocil Date: Wed, 5 Dec 2012 05:27:11 +0100 Subject: [PATCH] Improved --check-status + HTTP error + stdout redirect warning. --- httpie/core.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/httpie/core.py b/httpie/core.py index 5678d6c8..3d1e9438 100644 --- a/httpie/core.py +++ b/httpie/core.py @@ -60,9 +60,10 @@ def main(args=sys.argv[1:], env=Environment()): if env.config.default_options: args = env.config.default_options + args - def error(msg, *args): + def error(msg, *args, **kwargs): 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 traceback = debug or '--traceback' in args @@ -81,8 +82,12 @@ def main(args=sys.argv[1:], env=Environment()): if args.check_status: exit_status_code = get_exist_status_code(response.status_code, 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 = { 'stream': build_output_stream(