Better error handling
This commit is contained in:
parent
1461d12f4b
commit
b6957ca04a
3 changed files with 17 additions and 10 deletions
|
@ -1,3 +1,4 @@
|
|||
argcomplete==2.0.0
|
||||
requests==2.27.1
|
||||
pyyaml==5.4.1
|
||||
requests==2.27.1
|
||||
simplejson==3.17.6
|
||||
|
|
|
@ -13,7 +13,9 @@ from typing import Union
|
|||
import argcomplete
|
||||
import requests
|
||||
import yaml
|
||||
from requests.exceptions import JSONDecodeError as RequestsJSONDecodeError
|
||||
from requests.models import HTTPBasicAuth
|
||||
from simplejson.errors import JSONDecodeError as SimplejsonJSONDecodeError
|
||||
|
||||
|
||||
# Helper functions
|
||||
|
@ -241,6 +243,7 @@ def main() -> int:
|
|||
if 'ttl' in args:
|
||||
ttl = args.ttl
|
||||
url = setup_url(baseurl, args.data, args.name, args.rtype, ttl, args.zone)
|
||||
try:
|
||||
if args.command == "add":
|
||||
run_add(url, args.json, headers)
|
||||
elif args.command == "delete":
|
||||
|
@ -249,6 +252,9 @@ def main() -> int:
|
|||
run_list(url, args.json, headers)
|
||||
elif args.command == "update":
|
||||
run_update(url, args.json, headers)
|
||||
except (RequestsJSONDecodeError, SimplejsonJSONDecodeError):
|
||||
output(
|
||||
error("Could not decode api response as JSON", "Could not decode"))
|
||||
return 0
|
||||
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
[DEFAULT]
|
||||
Depends3: python3-argcomplete, python3-requests, python3-yaml
|
||||
Depends3: python3-argcomplete, python3-requests, python3-simplejson, python3-yaml
|
||||
Debian-Version: 1
|
||||
Package3: knotctl
|
||||
|
|
Loading…
Add table
Reference in a new issue