Small refactor and isort+black formatting
This commit is contained in:
@@ -1,22 +1,46 @@
|
||||
from pyrmv.errors.api_errors import ApiAuthError, ApiFormatError, ApiParamError, ApiQuotaError, ApiTooManyRequests
|
||||
from pyrmv.errors.int_errors import IntError, IntGatewayError, IntTimeoutError
|
||||
from pyrmv.errors.ps_errors import PsIncorrectParamError
|
||||
from pyrmv.errors.sot_errors import SotAllTrainsFilteredError, SotAlreadyArrivedError, SotCancelledError, SotNotStartedError, SotStayOnTripError
|
||||
from pyrmv.errors.svc_errors import SvcContextError, SvcDatetimeError, SvcDatetimePeriodError, SvcLocationArrivalError, SvcLocationDepartureError, SvcLocationEqualError, SvcLocationError, SvcLocationNearError, SvcLocationViaError, SvcNoMatchError, SvcNoResultError, SvcProductError, SvcSearchError
|
||||
from pyrmv.errors.unknown_error import UnknownError
|
||||
from pyrmv.errors import (
|
||||
ApiAuthError,
|
||||
ApiFormatError,
|
||||
ApiParamError,
|
||||
ApiQuotaError,
|
||||
ApiTooManyRequests,
|
||||
IntError,
|
||||
IntGatewayError,
|
||||
IntTimeoutError,
|
||||
PsIncorrectParamError,
|
||||
SotAllTrainsFilteredError,
|
||||
SotAlreadyArrivedError,
|
||||
SotCancelledError,
|
||||
SotNotStartedError,
|
||||
SotStayOnTripError,
|
||||
SvcContextError,
|
||||
SvcDatetimeError,
|
||||
SvcDatetimePeriodError,
|
||||
SvcLocationArrivalError,
|
||||
SvcLocationDepartureError,
|
||||
SvcLocationEqualError,
|
||||
SvcLocationError,
|
||||
SvcLocationNearError,
|
||||
SvcLocationViaError,
|
||||
SvcNoMatchError,
|
||||
SvcNoResultError,
|
||||
SvcProductError,
|
||||
SvcSearchError,
|
||||
UnknownError,
|
||||
)
|
||||
|
||||
|
||||
def find_exception(data: dict):
|
||||
"""Scan returned dict for errorCode from RMV.
|
||||
Raises different exceptions if errorCode is not None.
|
||||
Raises different exceptions if errorCode is not None.
|
||||
|
||||
### Args:
|
||||
* data (dict): Response from RMV as a dict.
|
||||
|
||||
### Raises:
|
||||
* Any: Formatted as "errorCode -> errorText" if ApiParamError and UnknownError or as a single massage for others.
|
||||
"""
|
||||
"""
|
||||
if "errorCode" in data:
|
||||
|
||||
if data["errorCode"] == "API_AUTH":
|
||||
raise ApiAuthError()
|
||||
|
||||
@@ -25,7 +49,7 @@ def find_exception(data: dict):
|
||||
|
||||
elif data["errorCode"] == "API_TOO_MANY_REQUESTS":
|
||||
raise ApiTooManyRequests()
|
||||
|
||||
|
||||
elif data["errorCode"] == "API_PARAM":
|
||||
raise ApiParamError(errorCode=data["errorCode"], errorText=data["errorText"])
|
||||
|
||||
@@ -99,4 +123,4 @@ def find_exception(data: dict):
|
||||
raise PsIncorrectParamError()
|
||||
|
||||
else:
|
||||
raise UnknownError(errorCode=data["errorCode"], errorText=data["errorText"])
|
||||
raise UnknownError(errorCode=data["errorCode"], errorText=data["errorText"])
|
||||
|
Reference in New Issue
Block a user