55module TzBot.Slack
66 ( BotM (.. )
77 , runBotM
8- , runOrThrowBotM
98 , AppLevelToken (.. )
109 , BotToken (.. )
1110 , BotState (.. )
@@ -24,7 +23,6 @@ module TzBot.Slack
2423
2524import Universum hiding (toString )
2625
27- import Control.Monad.Except (throwError )
2826import Data.Aeson (Value )
2927import Data.ByteString.UTF8 (toString )
3028import Data.DList qualified as DList
@@ -40,13 +38,13 @@ import Servant.Client.Core
4038 (ClientError (FailureResponse ), ResponseF (responseHeaders , responseStatusCode ))
4139import Text.Interpolation.Nyan (int , rmode' , rmode's )
4240import Time.Units (sec , threadDelay )
41+ import UnliftIO.Exception qualified as UnliftIO
4342
4443import TzBot.Cache qualified as Cache
4544import TzBot.Config
4645import TzBot.Logger
4746import TzBot.RunMonad
48- (BotException (.. ), BotM (.. ), BotState (.. ), ErrorDescription , runBotM , runKatipWithBotState ,
49- runOrThrowBotM )
47+ (BotException (.. ), BotM (.. ), BotState (.. ), ErrorDescription , runBotM , runKatipWithBotState )
5048import TzBot.Slack.API
5149 (ChannelId , Cursor , Limit (.. ), Message (.. ), MessageId (.. ), OpenViewReq (.. ), PostEphemeralReq (.. ),
5250 PostMessageReq (.. ), SlackContents (.. ), SlackResponse (.. ), ThreadId , UpdateViewReq (.. ), User ,
@@ -107,7 +105,7 @@ retrieveOneMessage channelId messageId = do
107105 case safeHead msgs of
108106 Just msg -> pure msg
109107 Nothing ->
110- throwError $
108+ UnliftIO. throwIO $
111109 UnexpectedResult endpointName functionName
112110 $ mkErrorMessage messageId Nothing
113111
@@ -133,7 +131,7 @@ retrieveOneMessageFromThread channelId threadId messageId = do
133131 case find (\ m -> mMessageId m == messageId) msgs of
134132 Just msg -> pure msg
135133 Nothing ->
136- throwError $
134+ UnliftIO. throwIO $
137135 UnexpectedResult endpointName functionName
138136 $ mkErrorMessage messageId $ Just threadId
139137
@@ -175,7 +173,7 @@ handleSlackError endpoint = \case
175173 SRSuccess a -> pure a
176174 SRError err_ metadata -> do
177175 logError [int ||#{endpoint} error: #{err_}; metadata: #s{metadata}|]
178- throwError $ EndpointFailed endpoint err_
176+ UnliftIO. throwIO $ EndpointFailed endpoint err_
179177
180178handleSlackErrorSingle :: Text -> SlackResponse $ SlackContents key a -> BotM a
181179handleSlackErrorSingle endpoint = fmap scContents . handleSlackError endpoint
@@ -261,8 +259,8 @@ usersInfo
261259 handleTooManyRequests (runClientM act clientEnv)) (cMaxRetries config)) >>= \ case
262260 Right a -> pure a
263261 Left clientError -> do
264- logError [int ||Client call failed: ${show @Text clientError}|]
265- throwError $ ServantError clientError
262+ logError [int ||Client call failed: #s{ clientError}|]
263+ UnliftIO. throwIO clientError
266264
267265-- | Handles slack API response with status code 429 @Too many requests@.
268266-- If action result is success, then return result. If action result is error
0 commit comments