Skip to content

Commit

Permalink
Handle 503 error (#3004)
Browse files Browse the repository at this point in the history
  • Loading branch information
YevheniiSemendiak authored Nov 13, 2023
1 parent da56f6f commit 0367d02
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion neuro-cli/src/neuro_cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ def main(args: Optional[List[str]] = None) -> None:
log.exception(f"Application error ({_err_to_str(error)})")
sys.exit(EX_SOFTWARE)

except neuro_sdk.ServerNotAvailable as error:
except neuro_sdk.BadGateway as error:
log.exception(f"Application error ({_err_to_str(error)})")
sys.exit(EX_PLATFORMERROR)

Expand Down
2 changes: 2 additions & 0 deletions neuro-sdk/src/neuro_sdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
AuthenticationError,
AuthError,
AuthorizationError,
BadGateway,
ClientError,
ConfigError,
IllegalArgumentError,
Expand Down Expand Up @@ -165,6 +166,7 @@
"AuthError",
"AuthenticationError",
"AuthorizationError",
"BadGateway",
"BlobCommonPrefix",
"BlobObject",
"Bucket",
Expand Down
4 changes: 3 additions & 1 deletion neuro-sdk/src/neuro_sdk/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from ._errors import (
AuthenticationError,
AuthorizationError,
BadGateway,
ClientError,
IllegalArgumentError,
ResourceNotFound,
Expand Down Expand Up @@ -77,7 +78,8 @@ def __init__(
403: AuthorizationError,
404: ResourceNotFound,
405: ClientError,
502: ServerNotAvailable,
502: BadGateway,
503: ServerNotAvailable,
}
self._prev_cookie: Optional[Morsel[str]] = None

Expand Down
5 changes: 5 additions & 0 deletions neuro-sdk/src/neuro_sdk/_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ class ServerNotAvailable(ValueError):
pass


@rewrite_module
class BadGateway(ValueError):
pass


@rewrite_module
class ConfigLoadException(Exception):
pass
Expand Down
4 changes: 2 additions & 2 deletions neuro-sdk/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from aiohttp import web
from yarl import URL

from neuro_sdk import IllegalArgumentError, ServerNotAvailable
from neuro_sdk import BadGateway, IllegalArgumentError
from neuro_sdk._core import (
_Core,
_ensure_schema,
Expand Down Expand Up @@ -125,7 +125,7 @@ async def handler(request: web.Request) -> web.Response:

async with api_factory(srv.make_url("/")) as api:
url = srv.make_url("test")
with pytest.raises(ServerNotAvailable, match="^502: Bad Gateway$"):
with pytest.raises(BadGateway, match="^502: Bad Gateway$"):
async with api.request(method="GET", url=url, auth="auth") as resp:
assert resp.status == 200

Expand Down

0 comments on commit 0367d02

Please sign in to comment.