From 4ee34b49a0130b43c0fc4ec01c44f45fdae00eca Mon Sep 17 00:00:00 2001 From: Philipp Balzarek Date: Tue, 12 Jun 2012 14:15:25 +0200 Subject: [PATCH] add error handling to Bind --- source/Network/Xmpp/Bind.hs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/source/Network/Xmpp/Bind.hs b/source/Network/Xmpp/Bind.hs index 6fb2860..cebec16 100644 --- a/source/Network/Xmpp/Bind.hs +++ b/source/Network/Xmpp/Bind.hs @@ -1,11 +1,13 @@ +{-# LANGUAGE PatternGuards #-} {-# LANGUAGE OverloadedStrings #-} {-# OPTIONS_HADDOCK hide #-} module Network.Xmpp.Bind where -import Data.Text as Text +import Control.Exception +import Data.Text as Text import Data.XML.Pickle import Data.XML.Types @@ -29,8 +31,11 @@ bindBody = pickleElem $ xmppBind :: Maybe Text -> XmppConMonad Jid xmppBind rsrc = do answer <- xmppSendIQ' "bind" Nothing Set Nothing (bindBody rsrc) - let Right IQResult{iqResultPayload = Just b} = answer -- TODO: Error handling - let Right jid = unpickleElem jidP b + jid <- case () of () | Right IQResult{iqResultPayload = Just b} <- answer + , Right jid <- unpickleElem jidP b + -> return jid + | otherwise -> throw $ StreamXMLError + "Bind could'nt unpickle JID" modify (\s -> s{sJid = Just jid}) return jid where