edts.py: proper handling for malformed system names
This commit is contained in:
parent
92eb2c9008
commit
718194ccec
1 changed files with 12 additions and 12 deletions
24
edts.py
24
edts.py
|
@ -10,21 +10,18 @@ from pyEDSM.edsm.exception import ServerError, NotFoundError
|
||||||
|
|
||||||
# ===========================================================================
|
# ===========================================================================
|
||||||
|
|
||||||
def querystations(url, params):
|
class ProcGenNameError(Exception):
|
||||||
response = requests.post(url, params)
|
def __str__(self):
|
||||||
if response.status_code != 200:
|
return "Given system is not a valid proc gen name."
|
||||||
raise ServerError(url, params)
|
|
||||||
json = response.json()
|
|
||||||
if json["count"] == 0:
|
|
||||||
raise NotFoundError()
|
|
||||||
return json
|
|
||||||
|
|
||||||
# ===========================================================================
|
|
||||||
|
|
||||||
def getCoords(system):
|
def getCoords(system):
|
||||||
response = requests.get(APIURLS["coords"] + urllib.parse.quote(system))
|
url = APIURLS["coords"] + urllib.parse.quote(system)
|
||||||
|
response = requests.get(url)
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
raise ServerError(url, params)
|
if response.status_code == 400:
|
||||||
|
raise ProcGenNameError()
|
||||||
|
else:
|
||||||
|
raise ServerError(url, {})
|
||||||
|
|
||||||
json = response.json()['result']
|
json = response.json()['result']
|
||||||
|
|
||||||
|
@ -68,6 +65,9 @@ try:
|
||||||
except ServerError as e:
|
except ServerError as e:
|
||||||
print(e)
|
print(e)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
except ProcGenNameError as e:
|
||||||
|
print(e)
|
||||||
|
sys.exit(4)
|
||||||
except NotFoundError as e:
|
except NotFoundError as e:
|
||||||
print("Maximum uncertainty exceeded: " + str(int(coords['uncertainty']))
|
print("Maximum uncertainty exceeded: " + str(int(coords['uncertainty']))
|
||||||
+ " > " + str(args.maxuncertainty))
|
+ " > " + str(args.maxuncertainty))
|
||||||
|
|
Loading…
Reference in a new issue