Skip to content

Commit

Permalink
Support for Rate Limits Exception (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
ashwin1111 authored Jan 27, 2023
1 parent dbe4a6f commit c2291d3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
1 change: 1 addition & 0 deletions netsuitesdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
'NetSuiteLoginError',
'NetSuiteRequestError',
'NetSuiteTypeError',
'NetSuiteRateLimitError'
]

name = "netsuitesdk"
23 changes: 16 additions & 7 deletions netsuitesdk/internal/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,13 +335,22 @@ def request(self, name, *args, **kwargs):
:return: the request response object
:rtype: the exact type depends on the request
"""
method = getattr(self._service_proxy, name)
# call the service:
include_search_preferences = (name == 'search')
response = method(*args,
_soapheaders=self._build_soap_headers(include_search_preferences=include_search_preferences)
, **kwargs)
return response
try:
method = getattr(self._service_proxy, name)
# call the service:
include_search_preferences = (name == 'search')
response = method(*args,
_soapheaders=self._build_soap_headers(include_search_preferences=include_search_preferences)
, **kwargs)
return response
except Fault as e:
if 'SuiteTalk concurrent request limit exceeded. Request blocked' in str(e):
raise NetSuiteRateLimitError(str(e))
else:
raise
except Exception as e:
raise


def get(self, recordType, internalId=None, externalId=None):
"""
Expand Down
8 changes: 7 additions & 1 deletion netsuitesdk/internal/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
:class:`NetSuiteLoginError`
:class:`NetSuiteRequestError`
:class:`NetSuiteTypeError`
:class:`NetSuiteRateLimitError`
"""

class NetSuiteError(Exception):
Expand Down Expand Up @@ -38,4 +39,9 @@ class NetSuiteRequestError(NetSuiteError):
class NetSuiteTypeError(NetSuiteError):
"""Exception raised when requested an invalid netsuite type"""

pass
pass

class NetSuiteRateLimitError(NetSuiteError):
"""Exception raised for errors during rate limit requests like get, search, .."""

pass

0 comments on commit c2291d3

Please sign in to comment.