Browse Source

add error handling to Bind

master
Philipp Balzarek 14 years ago
parent
commit
4ee34b49a0
  1. 11
      source/Network/Xmpp/Bind.hs

11
source/Network/Xmpp/Bind.hs

@ -1,11 +1,13 @@
{-# LANGUAGE PatternGuards #-}
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}
{-# OPTIONS_HADDOCK hide #-} {-# OPTIONS_HADDOCK hide #-}
module Network.Xmpp.Bind where 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.Pickle
import Data.XML.Types import Data.XML.Types
@ -29,8 +31,11 @@ bindBody = pickleElem $
xmppBind :: Maybe Text -> XmppConMonad Jid xmppBind :: Maybe Text -> XmppConMonad Jid
xmppBind rsrc = do xmppBind rsrc = do
answer <- xmppSendIQ' "bind" Nothing Set Nothing (bindBody rsrc) answer <- xmppSendIQ' "bind" Nothing Set Nothing (bindBody rsrc)
let Right IQResult{iqResultPayload = Just b} = answer -- TODO: Error handling jid <- case () of () | Right IQResult{iqResultPayload = Just b} <- answer
let Right jid = unpickleElem jidP b , Right jid <- unpickleElem jidP b
-> return jid
| otherwise -> throw $ StreamXMLError
"Bind could'nt unpickle JID"
modify (\s -> s{sJid = Just jid}) modify (\s -> s{sJid = Just jid})
return jid return jid
where where

Loading…
Cancel
Save