1
0
mirror of https://github.com/httpie/cli.git synced 2024-11-24 08:22:22 +02:00

Added error handling.

This commit is contained in:
Jakub Roztočil 2012-02-26 16:13:12 +01:00
parent 4059dbc27a
commit 98e320a1a3
2 changed files with 26 additions and 12 deletions

View File

@ -56,6 +56,9 @@ group_type.add_argument('--form', '-f', action='store_true',
' if not specified.')
# Output options.
parser.add_argument('--traceback', action='store_true', default=False,
help='Print a full exception traceback should one'
' be raised by `requests`.')
parser.add_argument('--ugly', '-u', help='Do not prettify the response.',
dest='prettify', action='store_false', default=True)
group_only = parser.add_mutually_exclusive_group(required=False)
@ -131,6 +134,7 @@ def main():
headers['Content-Type'] = TYPE_FORM
# Fire the request.
try:
response = requests.request(
method=args.method.lower(),
url=args.url if '://' in args.url else 'http://%s' % args.url,
@ -142,6 +146,14 @@ def main():
proxies={proxy.key: proxy.value for proxy in args.proxy},
files={os.path.basename(f.name): f for f in args.file}
)
except (KeyboardInterrupt, SystemExit) as e:
sys.stderr.write('\n')
sys.exit(1)
except Exception as e:
if args.traceback:
raise
sys.stderr.write(str(e.message) + '\n')
sys.exit(1)
# Display the response.
original = response.raw._original_response

View File

@ -5,6 +5,7 @@ from pygments.lexers import get_lexer_for_mimetype
from pygments.formatters.terminal256 import Terminal256Formatter
from pygments.lexer import RegexLexer, bygroups
from pygments import token
from . import solarized
TYPE_JS = 'application/javascript'
@ -24,7 +25,8 @@ class HTTPLexer(RegexLexer):
highlight = partial(pygments.highlight,
formatter=Terminal256Formatter(style='native'))
formatter=Terminal256Formatter(
style=solarized.SolarizedStyle))
highlight_http = partial(highlight, lexer=HTTPLexer())