Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Censor error message and change LonkWsSubscription #575

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions chris_backend/pacsfiles/consumers.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ async def _subscribe(self, pacs_name: str, series_instance_uid: str):
response = Lonk(
pacs_name=pacs_name,
SeriesInstanceUID=series_instance_uid,
message=LonkWsSubscription(subscription='subscribed'),
message=LonkWsSubscription(subscribed=True),
)
await self.send_json(response)
except Exception as e:
response = Lonk(
pacs_name=pacs_name,
SeriesInstanceUID=series_instance_uid,
message=LonkWsSubscription(subscription='error'),
message=LonkWsSubscription(subscribed=False),
)
await self.send_json(response)
await self.close(code=500)
Expand Down
10 changes: 7 additions & 3 deletions chris_backend/pacsfiles/lonk.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"""
import asyncio
import enum
from sys import byteorder
import logging
from typing import (
Self,
Callable,
Expand All @@ -21,6 +21,8 @@
from nats.aio.subscription import Subscription
from nats.aio.msg import Msg

logger = logging.getLogger(__name__)


class SubscriptionRequest(TypedDict):
"""
Expand Down Expand Up @@ -79,7 +81,7 @@ class LonkWsSubscription(TypedDict):
https://chrisproject.org/docs/oxidicom/lonk-ws#lonk-ws-subscription
"""

subscription: Literal['subscribed', 'error']
subscribed: bool


LonkMessageData = LonkProgress | LonkError | LonkDone | LonkWsSubscription
Expand Down Expand Up @@ -202,7 +204,9 @@ def _serialize_to_lonkws(payload: bytes) -> LonkMessageData:
ndicom = int.from_bytes(data, 'little', signed=False)
return LonkProgress(ndicom=ndicom)
case LonkMagicByte.ERROR.value:
error = data.decode(encoding='utf-8')
msg = data.decode(encoding='utf-8')
logger.error(f'Error from oxidicom: {msg}')
error = 'oxidicom reported an error, check logs for details.'
return LonkError(error=error)
case _:
hexstr = ' '.join(hex(b) for b in payload)
Expand Down
7 changes: 4 additions & 3 deletions chris_backend/pacsfiles/tests/test_consumers.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ async def test_lonk_ws(self):
self.assertEqual(
await communicator.receive_json_from(),
Lonk(
message=LonkWsSubscription(subscription='subscribed'),
message=LonkWsSubscription(subscribed=True),
**series1,
),
)
Expand All @@ -69,7 +69,7 @@ async def test_lonk_ws(self):
self.assertEqual(
await communicator.receive_json_from(),
Lonk(
message=LonkWsSubscription(subscription='subscribed'),
message=LonkWsSubscription(subscribed=True),
**series2,
),
)
Expand All @@ -86,9 +86,10 @@ async def test_lonk_ws(self):
)

await oxidicom.send_error(error='stuck in chimney', **series2)
expected = 'oxidicom reported an error, check logs for details.'
self.assertEqual(
await communicator.receive_json_from(),
Lonk(message=LonkError(error='stuck in chimney'), **series2),
Lonk(message=LonkError(error=expected), **series2),
)

await oxidicom.send_progress(ndicom=192, **series1)
Expand Down
Loading