Skip to content

Commit

Permalink
small adjustment to error logging. The 'DocStatus' error occurs while…
Browse files Browse the repository at this point in the history
… working with already committed Avalara document codes. These should be returned as errors to the codebase, however should not be logged as exceptions that need to be watched. ver bump
  • Loading branch information
jobelenus committed Nov 16, 2015
1 parent 81e00dc commit 11c37f3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pyavatax/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION = (1, 3, 2)
VERSION = (1, 3, 3)


from .api import API
Expand Down
30 changes: 25 additions & 5 deletions pyavatax/api.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,41 @@
import decorator
import json
from pyavatax.base import Document, Address, BaseResponse, BaseAPI, AvalaraException, AvalaraTypeException, AvalaraValidationException, AvalaraServerException, ErrorResponse


@decorator.decorator
def except_500_and_return(fn, *args, **kwargs):
try:
return fn(*args, **kwargs)
except AvalaraServerException as e:
self = args[0] # the first arg is self
self.logger.error(e.full_request_as_string)

def error_as_resp(args, e):
"""
Always return the error wrapped in a response object
"""
resp = ErrorResponse(e.response)
for arg in args:
if isinstance(arg, Document):
self.recorder.failure(arg, resp)
break
return resp

try:
return fn(*args, **kwargs)
except AvalaraServerException as e:
self = args[0] # the first arg is self
logged = False
try:
# but don't log the doc status error as an exception
error_as_json = json.loads(e.full_request_as_string)
if 'DocStatus' in error_as_json:
if error_as_json == 'DocStatus is invalid for this operation.':
self.logger.warning(e.full_request_as_string) # this case is not an error, just log a warning
logged = True

if not logged:
self.logger.exception(e.full_request_as_string)
return error_as_resp(args, e)
except ValueError: # json failed to parse
self.logger.exception(e.full_request_as_string)
return error_as_resp(args, e)

class API(BaseAPI):

Expand Down

0 comments on commit 11c37f3

Please sign in to comment.