Skip to content

Commit

Permalink
Handle return code and exceptions better
Browse files Browse the repository at this point in the history
  • Loading branch information
pawamoy committed Dec 23, 2018
1 parent 0e45e6f commit 14f47f8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/aria2p/__main__.py
Expand Up @@ -13,4 +13,4 @@
from aria2p.cli import main

if __name__ == "__main__":
main(sys.argv[1:])
sys.exit(main(sys.argv[1:]))
11 changes: 8 additions & 3 deletions src/aria2p/cli.py
Expand Up @@ -69,18 +69,23 @@ def main(args=None):
params = json.loads(args.json_params)
if method is None:
print(f"Unknown method {args.method}. Run '{sys.argv[0]} -m listmethods' to list the available methods.")
sys.exit(1)
return 1
try:
response = client.call(method, params)
except JSONRPCError as e:
print(e.message)
sys.exit(e.code)
return e.code
else:
print(json.dumps(response))
return 0

api = API(client)
downloads = api.get_downloads()

try:
downloads = api.get_downloads()
except Exception as e:
print(e)
return 1

print(f"{'GID':<17} {'STATUS':<9} {'PROGRESS':<8} {'DOWN_SPEED':<12} {'ETA':<8} NAME")
for download in downloads:
Expand Down

0 comments on commit 14f47f8

Please sign in to comment.