Skip to content

Commit d95ab6d

Browse files
committed
Refactor
Signed-off-by: Sasha Bogicevic <[email protected]>
1 parent 5d2c364 commit d95ab6d

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

hydra-node/src/Hydra/API/WSServer.hs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,17 +174,19 @@ wsApp env party tracer chain history callback nodeStateP networkInfoP responseCh
174174
Right input -> do
175175
traceWith tracer (APIInputReceived $ toJSON input)
176176
NodeState{headState} <- atomically getLatestNodeState
177-
case HeadState.getOpenStateConfirmedSnapshot headState of
178-
Nothing -> callback input
179-
Just confirmedSnapshot ->
180-
case input of
181-
SafeClose -> do
177+
case input of
178+
SafeClose ->
179+
case HeadState.getOpenStateConfirmedSnapshot headState of
180+
Nothing -> callback input
181+
Just confirmedSnapshot ->
182182
case checkNonADAAssets confirmedSnapshot of
183183
Left nonADAValue -> do
184184
let clientInput = decodeUtf8With lenientDecode $ toStrict msg
185-
traceWith tracer (APIInvalidInput ("Cannot SafeClose with non-ADA assets present: " <> show nonADAValue) clientInput)
185+
let errorStr = "Cannot SafeClose with non-ADA assets present: " <> show nonADAValue
186+
sendTextData con $ Aeson.encode $ InvalidInput errorStr clientInput
187+
traceWith tracer (APIInvalidInput errorStr clientInput)
186188
Right _ -> callback input
187-
_ -> callback input
189+
_ -> callback input
188190
Left e -> do
189191
-- XXX(AB): toStrict might be problematic as it implies consuming the full
190192
-- message to memory

0 commit comments

Comments
 (0)