Skip to content

Commit

Permalink
fix: raise UsageError (#165)
Browse files Browse the repository at this point in the history
* fix: raise UsageError

* refactor: ClientError

* fix: import

* fix: add note
  • Loading branch information
dtdang authored Nov 1, 2024
1 parent a83e107 commit 8fc21d8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion silverback/cluster/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from apepay import Stream, StreamManager
from pydantic import computed_field

from silverback.exceptions import ClientError
from silverback.version import version

from .types import (
Expand Down Expand Up @@ -54,7 +55,7 @@ def render_error(error: dict):
else:
message = response.text

raise RuntimeError(message)
raise ClientError(message)

response.raise_for_status()

Expand Down
6 changes: 6 additions & 0 deletions silverback/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Any

import click
from ape.exceptions import ApeException

from .types import TaskType
Expand Down Expand Up @@ -41,6 +42,11 @@ def __init__(self, *exceptions: Exception | str):
super().__init__("Startup failure(s) detected. See logs for details.")


# NOTE: Subclass `click.UsageError` here so bad requests in CLI don't show stack trace
class ClientError(SilverbackException, click.UsageError):
"""Exception for client errors in the HTTP request."""


class NoTasksAvailableError(SilverbackException):
def __init__(self):
super().__init__("No tasks to execute")
Expand Down

0 comments on commit 8fc21d8

Please sign in to comment.