Skip to content

Commit

Permalink
DynamicApiError: add a summary method (openshift#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
pilou- authored and willthames committed Nov 22, 2018
1 parent 94f2700 commit df3111b
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions openshift/dynamic/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import sys
import traceback

Expand Down Expand Up @@ -49,6 +50,17 @@ def __str__(self):

return '\n'.join(error_message)

def summary(self):
if self.body:
if self.headers and self.headers.get('Content-Type') == 'application/json':
message = json.loads(self.body).get('message')
if message:
return message

return self.body
else:
return "{} Reason: {}".format(self.status, self.reason)

class ResourceNotFoundError(Exception):
""" Resource was not found in available APIs """
class ResourceNotUniqueError(Exception):
Expand Down

0 comments on commit df3111b

Please sign in to comment.