Skip to content

Improve error messages #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions prexview.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ def __send(self, data):

response = post(self._URL + 'transform', data = data, headers = headers)

if response.raise_for_status() is not None:
return None
if response.status_code != 200:
raise Exception(loads(response.content)['error'])

result = {
'rateLimit': response.headers['x-ratelimit-limit'],
'rateLimitReset': response.headers['x-ratelimit-reset'],
'rateRemaining': response.headers['x-ratelimit-remaining'],
}

if response.status_code is 200:
if response.status_code == 200:
result['id'] = response.headers['x-transaction-id']
result['file'] = response.content
result['responseTime'] = response.headers['x-response-time']
Expand All @@ -47,14 +47,14 @@ def __send(self, data):
def __isJson(self, str):
try:
json = loads(str)
except ValueError, e:
except ValueError as e:
return False

return True

def __checkOptions(self, _format, options):
# JSON
if _format is 'json':
if _format == 'json':
if type(options['json']) is str:
if self.__isJson(options['json']) is not True:
raise Exception('PrexView content must be a valid JSON string')
Expand Down Expand Up @@ -104,7 +104,7 @@ def __checkOptions(self, _format, options):
return options

def __checkToken(self):
if self.token is None or self.token is '':
if self.token is None or self.token == '':
raise Exception('PrexView environment variable PXV_API_KEY must be set')

def sendXML(self, content, options):
Expand Down
8 changes: 4 additions & 4 deletions tests/test_json.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# coding: utf-8
from prexview import Prexview
from prexview import PrexView

pxv = Prexview()
pxv = PrexView()
options = {'design': 'custom-invoice', 'output': 'pdf'}

json = {
Expand All @@ -21,6 +21,6 @@
f.write(res['file'])
f.close()

print 'File created:', file
print('File created:', file)
except Exception as e:
print e
print(e)
8 changes: 4 additions & 4 deletions tests/test_xml.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# coding: utf-8
from prexview import Prexview
from prexview import PrexView

pxv = Prexview()
pxv = PrexView()
options = dict(design='custom-invoice', output='pdf')

xml = '''<?xml version="1.0" encoding="UTF-8"?>
Expand All @@ -20,6 +20,6 @@
f.write(res['file'])
f.close()

print 'File created:', file
print('File created:', file)
except Exception as e:
print e
print(e)