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:
parent
4059dbc27a
commit
98e320a1a3
@ -56,6 +56,9 @@ group_type.add_argument('--form', '-f', action='store_true',
|
|||||||
' if not specified.')
|
' if not specified.')
|
||||||
|
|
||||||
# Output options.
|
# 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.',
|
parser.add_argument('--ugly', '-u', help='Do not prettify the response.',
|
||||||
dest='prettify', action='store_false', default=True)
|
dest='prettify', action='store_false', default=True)
|
||||||
group_only = parser.add_mutually_exclusive_group(required=False)
|
group_only = parser.add_mutually_exclusive_group(required=False)
|
||||||
@ -131,17 +134,26 @@ def main():
|
|||||||
headers['Content-Type'] = TYPE_FORM
|
headers['Content-Type'] = TYPE_FORM
|
||||||
|
|
||||||
# Fire the request.
|
# Fire the request.
|
||||||
response = requests.request(
|
try:
|
||||||
method=args.method.lower(),
|
response = requests.request(
|
||||||
url=args.url if '://' in args.url else 'http://%s' % args.url,
|
method=args.method.lower(),
|
||||||
headers=headers,
|
url=args.url if '://' in args.url else 'http://%s' % args.url,
|
||||||
data=data,
|
headers=headers,
|
||||||
verify=True if args.verify == 'yes' else args.verify,
|
data=data,
|
||||||
timeout=args.timeout,
|
verify=True if args.verify == 'yes' else args.verify,
|
||||||
auth=(args.auth.key, args.auth.value) if args.auth else None,
|
timeout=args.timeout,
|
||||||
proxies={proxy.key: proxy.value for proxy in args.proxy},
|
auth=(args.auth.key, args.auth.value) if args.auth else None,
|
||||||
files={os.path.basename(f.name): f for f in args.file}
|
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.
|
# Display the response.
|
||||||
original = response.raw._original_response
|
original = response.raw._original_response
|
||||||
|
@ -5,6 +5,7 @@ from pygments.lexers import get_lexer_for_mimetype
|
|||||||
from pygments.formatters.terminal256 import Terminal256Formatter
|
from pygments.formatters.terminal256 import Terminal256Formatter
|
||||||
from pygments.lexer import RegexLexer, bygroups
|
from pygments.lexer import RegexLexer, bygroups
|
||||||
from pygments import token
|
from pygments import token
|
||||||
|
from . import solarized
|
||||||
|
|
||||||
|
|
||||||
TYPE_JS = 'application/javascript'
|
TYPE_JS = 'application/javascript'
|
||||||
@ -24,7 +25,8 @@ class HTTPLexer(RegexLexer):
|
|||||||
|
|
||||||
|
|
||||||
highlight = partial(pygments.highlight,
|
highlight = partial(pygments.highlight,
|
||||||
formatter=Terminal256Formatter(style='native'))
|
formatter=Terminal256Formatter(
|
||||||
|
style=solarized.SolarizedStyle))
|
||||||
highlight_http = partial(highlight, lexer=HTTPLexer())
|
highlight_http = partial(highlight, lexer=HTTPLexer())
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user