-
Notifications
You must be signed in to change notification settings - Fork 3
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
added type hinting, document string, TODO statements, fixed small typ… #14
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
from .version import __version__ # noqa: F401 | ||
|
||
import six | ||
from typing import Optional | ||
|
||
try: | ||
import ujson as json # noqa: F401 | ||
|
@@ -49,15 +50,15 @@ class ClientExceptionBase(Exception): | |
""" | ||
_message = None # the error message, should be unicode | ||
|
||
def __init__(self, message=''): | ||
if message is not None and not isinstance(message, six.text_type): | ||
def __init__(self, message: Optional[str]='') -> None: | ||
if message is not None and not isinstance(message, six.text_type): | ||
message = message.decode('utf-8', 'ignore') | ||
self._message = message | ||
|
||
def __str__(self): | ||
def __str__(self) -> str: | ||
return u'%s: %s' % (self.__class__.__name__, self._message) | ||
|
||
def __repr__(self): | ||
def __repr__(self) -> str: | ||
return '<%s(message=%r)>' % (self.__class__.__name__, self._message) | ||
|
||
|
||
|
@@ -69,7 +70,7 @@ class APIServerError(ClientExceptionBase): | |
_detailInfo = None # dcit, the detailed info | ||
_inputcommand = None # the command sent to the server | ||
|
||
def __init__(self, message, errorcode=None, inputcommand=None, detailInfoType=None, detailInfo=None): | ||
def __init__(self, message: str, errorcode: Optional[int]=None, inputcommand: Optional[str]=None, detailInfoType: Optional[str]=None, detailInfo: Optional[dict]=None) -> None: | ||
if message is not None and not isinstance(message, six.text_type): | ||
message = message.decode('utf-8', 'ignore') | ||
self._message = message | ||
|
@@ -78,7 +79,7 @@ def __init__(self, message, errorcode=None, inputcommand=None, detailInfoType=No | |
self._detailInfoType = detailInfoType | ||
self._detailInfo = detailInfo | ||
|
||
def __str__(self): | ||
def __str__(self) -> str: | ||
if self._message is not None: | ||
return _('API Server Error: %s')%self._message | ||
|
||
|
@@ -88,7 +89,7 @@ def __repr__(self): | |
return '<%s(message=%r, errorcode=%r, inputcommand=%r, detailInfoType=%r, detailInfo=%r)>' % (self.__class__.__name__, self._message, self._errorcode, self._inputcommand, self._detailInfoType, self._detailInfo) | ||
|
||
@property | ||
def message(self): | ||
def message(self) -> str: | ||
"""The error message from server.""" | ||
return self._message | ||
|
||
|
@@ -98,16 +99,17 @@ def errorcode(self): | |
return self._errorcode | ||
|
||
@property | ||
def stacktrace(self): | ||
def stacktrace(self) -> str: | ||
"""The stack trace for the error""" | ||
return '' | ||
|
||
@property | ||
def inputcommand(self): | ||
def inputcommand(self) -> Optional[str]: | ||
"""The command that was sent to the server. Could be None.""" | ||
return self._inputcommand | ||
|
||
@property | ||
def detailInfoType(self): | ||
def detailInfoType(self) -> Optional[str]: | ||
"""string for the detai info type""" | ||
return self._detailInfoType | ||
|
||
|
@@ -125,7 +127,7 @@ class AuthenticationError(ClientExceptionBase): | |
|
||
|
||
class WebstackClientError(ClientExceptionBase): | ||
|
||
"""Exeption class for errors returned by the web stack client""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This wording makes me a bit uncomfortable since there's a few error types that a request could raise:
Perhaps this is better:
I hope this might disambiguate the GraphQL errors. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @hemangandhi I will take a look at it again |
||
_response = None # http response that resulted in the error | ||
|
||
def __init__(self, message='', response=None): | ||
|
@@ -134,6 +136,7 @@ def __init__(self, message='', response=None): | |
|
||
@property | ||
def response(self): | ||
"""The http response that resulted in the error""" | ||
return self._response | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the added space?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The space is indeed not needed.