Skip to content

Commit

Permalink
[http-] on errors, show fail msg instead of traceback
Browse files Browse the repository at this point in the history
  • Loading branch information
midichef committed Mar 25, 2024
1 parent 581cdf1 commit ca90ccd
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion visidata/loaders/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ def openurl_http(vd, path, filetype=None):
ctx.verify_mode = ssl.CERT_NONE

req = urllib.request.Request(path.given, **vd.options.getall('http_req_'))
response = urllib.request.urlopen(req, context=ctx)
try:
response = urllib.request.urlopen(req, context=ctx)
except urllib.error.HTTPError as e:
vd.fail(f'cannot open URL: HTTP Error {e.code}: {e.reason}')
except urllib.error.URLError as e:
vd.fail(f'cannot open URL: {e.reason}')

filetype = filetype or vd.guessFiletype(path, response, funcprefix='guessurl_').get('filetype') # try guessing by url
filetype = filetype or vd.guessFiletype(path, funcprefix='guess_').get('filetype') # try guessing by contents
Expand Down

0 comments on commit ca90ccd

Please sign in to comment.