diff --git a/silverback/cluster/client.py b/silverback/cluster/client.py index ff4cfc5b..a3a6c563 100644 --- a/silverback/cluster/client.py +++ b/silverback/cluster/client.py @@ -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 ( @@ -54,7 +55,7 @@ def render_error(error: dict): else: message = response.text - raise RuntimeError(message) + raise ClientError(message) response.raise_for_status() diff --git a/silverback/exceptions.py b/silverback/exceptions.py index 554f5a88..ffc6c6d3 100644 --- a/silverback/exceptions.py +++ b/silverback/exceptions.py @@ -1,5 +1,6 @@ from typing import Any +import click from ape.exceptions import ApeException from .types import TaskType @@ -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")