Small refactor and isort+black formatting
Some checks reported warnings
Tests / test (3.11) (push) Has been cancelled
Tests / test (3.8) (push) Has been cancelled
Tests / test (3.9) (push) Has been cancelled
Tests / test (3.10) (push) Has been cancelled

This commit is contained in:
2023-11-24 11:21:02 +01:00
parent fa4f7b83ec
commit f31fa65d78
45 changed files with 1035 additions and 923 deletions

View File

@@ -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"])