summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCédric Picard <cedric.picard@efrei.net>2014-11-29 10:41:39 +0100
committerCédric Picard <cedric.picard@efrei.net>2014-11-29 10:41:39 +0100
commitf56e87f100989554cd17ddd8dbf2d666a56ed468 (patch)
tree1bcf76ea96250bd13e4821d02989ed9f3a0f7ac2
parentd3d7c9c6e1bd12a6229fc03595911dbddb7a09f9 (diff)
downloadpasteme-f56e87f100989554cd17ddd8dbf2d666a56ed468.tar.gz
pasteme-f56e87f100989554cd17ddd8dbf2d666a56ed468.tar.bz2
pasteme-f56e87f100989554cd17ddd8dbf2d666a56ed468.zip
Better error management
-rwxr-xr-xscripts/pastit.py22
1 files changed, 18 insertions, 4 deletions
diff --git a/scripts/pastit.py b/scripts/pastit.py
index 63e5ab3..29aa3cd 100755
--- a/scripts/pastit.py
+++ b/scripts/pastit.py
@@ -25,8 +25,8 @@ from docopt import docopt
def post(text, url):
try:
req = requests.post(url, data={"content":text})
- except requests.exceptions.ConnectionError as e:
- sys.exit(e)
+ except BaseException as e:
+ manage(e, url)
return req.url
@@ -36,8 +36,8 @@ def get(url):
try:
req = requests.get(url)
- except requests.exceptions.ConnectionError as e:
- sys.exit(e)
+ except BaseException as e:
+ manage(e, url)
if req.status_code == 404:
return "Paste not found"
@@ -47,6 +47,20 @@ def get(url):
return req.text
+def manage(excep, url=None):
+ try:
+ raise excep
+ except requests.exceptions.ConnectionError as e:
+ sys.exit(e)
+ except (requests.exceptions.InvalidURL,
+ requests.exceptions.InvalidSchema) as e:
+ print("Invalid URL: %s" % url, file=sys.stderr)
+ if not url.startswith("http"):
+ print("Perhaps you meant http://%s" % url, file=sys.stderr)
+ sys.exit(1)
+
+
+
def main():
args = docopt(__doc__)