Skip to content

Commit d67750c

Browse files
committed
handle error response in Network.get_resource()
1 parent dbe71f3 commit d67750c

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

netfoundry/network.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -319,14 +319,14 @@ def share_endpoint(self,recipient,endpoint_id):
319319
)
320320

321321
def get_resource(self, type: str, id: str, accept: str=None):
322-
"""return an object describing an entity
322+
"""Return an object describing a resource entity.
323+
323324
:param type: required string of the singular of an entity type e.g. network, endpoint, service, edge-router, edge-router-policy, posture-check
324325
:param id: the UUID of the entity if not a network
325326
:param: accept: optional modifier string specifying the form of the desired response. Choices ["create","update"] where
326327
"create" is useful for comparing an existing entity to a set of properties that are used to create the same type of
327328
entity in a POST request, and "update" may be used in the same way for a PUT update.
328329
"""
329-
330330
# to singular if plural
331331
if type[-1] == "s":
332332
type = singular(type)
@@ -369,6 +369,14 @@ def get_resource(self, type: str, id: str, accept: str=None):
369369
entity = json.loads(response.text)
370370
except:
371371
raise Exception('ERROR parsing response as object, got:\n{}'.format(response.text))
372+
else:
373+
raise Exception(
374+
'ERROR: got unexpected HTTP code {:s} ({:d}) and response {:s}'.format(
375+
STATUS_CODES._codes[response_code][0].upper(),
376+
response_code,
377+
response.text
378+
)
379+
)
372380

373381
# routers are a special case because the value of entity._embedded.host.dataCenterId is expected by
374382
# downstream consumers of this method to be found at entity.dataCenterId
@@ -382,7 +390,8 @@ def get_resource(self, type: str, id: str, accept: str=None):
382390
return(entity)
383391

384392
def get_resources(self, type: str,name: str=None, accept: str=None, deleted: bool=False, typeId: str=None):
385-
"""return the resources object
393+
"""Find resources by type.
394+
386395
:param str type: plural of an entity type e.g. networks, endpoints, services, posture-checks, etc...
387396
:param str name: filter results by name
388397
:param str accept: specifying the form of the desired response. Choices ["create","update"] where
@@ -391,7 +400,6 @@ def get_resources(self, type: str,name: str=None, accept: str=None, deleted: boo
391400
:param bool deleted: include resource entities that have a non-null property deletedAt
392401
:param str typeId: filter results by typeId
393402
"""
394-
395403
# pluralize if singular
396404
if not type[-1] == "s":
397405
type = plural(type)

0 commit comments

Comments
 (0)