Skip to content

Commit

Permalink
Improve exception handling of 409: Conflicts.
Browse files Browse the repository at this point in the history
  • Loading branch information
Shea Craig committed Mar 26, 2015
1 parent 1633da4 commit f901ea3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
### 0.5.9 (March 26, 2015) The Pricing is the Message

CHANGES:

- Passes JSS error messages through when it returns 409: Conflict. Previously thought to be helpful, not passing along the response from the JSS was obfuscating the cause of the conflict. 409 Post and PUT Exceptions will now report back on the (first) error in the XML.

### 0.5.8 (March 19, 2015) Echo Sierra Xray India

FIXES:
Expand Down
2 changes: 1 addition & 1 deletion jss/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@
JSSUnsupportedSearchMethodError, JSSFileUploadParameterError,
JSSUnsupportedFileType)

__version__ = "0.5.8"
__version__ = "0.5.9"
21 changes: 5 additions & 16 deletions jss/jss.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ def _error_handler(self, exception_cls, response):
if e:
error.append(e.group(1))

error = '\n'.join(error)
exception = exception_cls('JSS Error. Response Code: %s\tResponse" %s'
error = '. '.join(error)
exception = exception_cls('Response Code: %s\tResponse: %s'
% (response.status_code, error))
exception.status_code = response.status_code
raise exception
Expand Down Expand Up @@ -626,13 +626,7 @@ def save(self):
updated_data = self.jss.post(self.__class__, url,
self)
except JSSPostError as e:
if e.status_code == 409:
raise JSSPostError(
"Object Conflict! If trying to post a new "
"object, look for name conflict and "
"delete.")
else:
raise JSSPostError(e)
raise JSSPostError(e)
else:
raise JSSMethodNotAllowedError(self.__class__.__name__)
else:
Expand All @@ -645,10 +639,7 @@ def save(self):
try:
updated_data = self.jss.post(self.__class__, url, self)
except JSSPostError as e:
if e.status_code == 409:
raise JSSPostError("Object Conflict! If trying to post a "
"new object, look for name conflict and"
" delete.")
raise JSSPostError(e)

# If successful, replace current instance's data with new,
# JSS-filled data.
Expand Down Expand Up @@ -1175,9 +1166,7 @@ def set_upload_url(self):
# files=self.resource)
# except JSSPostError as e:
# if e.status_code == 409:
# raise JSSPostError("Object Conflict! If trying to post a "
# "new object, look for name conflict and "
# "delete.")
# raise JSSPostError(e)
# else:
# raise JSSMethodNotAllowedError(self.__class__.__name__)

Expand Down

0 comments on commit f901ea3

Please sign in to comment.