From f767d1f8ff84c3509d0adeb27d9ca85a9e0859f2 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Mon, 19 Apr 2021 08:40:23 +0100 Subject: [PATCH] chat: add connection errors in chat, fix catch (#103) --- Main.hs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Main.hs b/Main.hs index b7127be0d5..f4100e9a18 100644 --- a/Main.hs +++ b/Main.hs @@ -90,6 +90,7 @@ data ChatResponse | ReceivedMessage Contact ByteString | Disconnected Contact | YesYes + | ContactError ConnectionErrorType Contact | ErrorInput ByteString | ChatError AgentErrorType | NoChatResponse @@ -110,6 +111,10 @@ serializeChatResponse = \case ReceivedMessage c t -> prependFirst (ttyFromContact c) $ msgPlain t Disconnected c -> ["disconnected from " <> ttyContact c <> " - try \"/chat " <> bPlain (toBs c) <> "\""] YesYes -> ["you got it!"] + ContactError e c -> case e of + UNKNOWN -> ["no contact " <> ttyContact c] + DUPLICATE -> ["contact " <> ttyContact c <> " already exists"] + SIMPLEX -> ["contact " <> ttyContact c <> " did not accept invitation yet"] ErrorInput t -> ["invalid input: " <> bPlain t] ChatError e -> ["chat error: " <> plain (show e)] NoChatResponse -> [""] @@ -256,6 +261,7 @@ receiveFromAgent t ct c = forever . atomically $ do MSG {m_body} -> ReceivedMessage contact m_body SENT _ -> NoChatResponse OK -> Confirmation contact + ERR (CONN e) -> ContactError e contact ERR e -> ChatError e where contact = Contact a