Skip to content

Commit

Permalink
bridge: unify RoutingError and CockpitProblem
Browse files Browse the repository at this point in the history
  • Loading branch information
allisonkarlitskaya committed Nov 22, 2023
1 parent 25a1509 commit 6314638
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/cockpit/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from typing import Dict, List, Optional

from .jsonutil import JsonDocument, JsonObject
from .protocol import CockpitProtocolError, CockpitProtocolServer
from .protocol import CockpitProblem, CockpitProtocolError, CockpitProtocolServer

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -104,10 +104,8 @@ def shutdown_endpoint(self, _msg: 'JsonObject | None' = None, **kwargs: JsonDocu
self.router.shutdown_endpoint(self, _msg, **kwargs)


class RoutingError(Exception):
def __init__(self, problem, **kwargs):
self.problem = problem
self.kwargs = kwargs
class RoutingError(CockpitProblem):
pass


class RoutingRule:
Expand Down Expand Up @@ -194,7 +192,7 @@ def channel_control_received(self, channel: str, command: str, message: JsonObje
logger.debug('Trying to find endpoint for new channel %s payload=%s', channel, message.get('payload'))
endpoint = self.check_rules(message)
except RoutingError as exc:
self.write_control(command='close', channel=channel, problem=exc.problem, **exc.kwargs)
self.write_control(exc.attrs, command='close', channel=channel)
return

self.open_channels[channel] = endpoint
Expand Down

0 comments on commit 6314638

Please sign in to comment.