Skip to content

Commit

Permalink
use ByteString for ElasticSearchExcetion
Browse files Browse the repository at this point in the history
  • Loading branch information
giantimi committed Feb 2, 2024
1 parent 39c2c9b commit ed3565b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions exec/TXG.hs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import qualified Data.Map as M
import Data.Maybe
import Data.Sequence.NonEmpty (NESeq(..))
import qualified Data.Sequence.NonEmpty as NES
import Data.String (fromString)
import Data.String.Conv (toS)
import Data.Text (Text)
import qualified Data.Text as T
Expand Down Expand Up @@ -552,7 +553,7 @@ esCheckIndex mgr logger esConf version = do
let indexCreated = object ["acknowledged" .= True, "shards_acknowledged" .= True, "index" .= indexName ]
if val == indexCreated && (status == 200 || status == 201)
then liftIO $ loggerFunIO logger Info $ "Index " <> T.pack indexName <> " created"
else throwM $ ElasticSearchException $ "esCheckIndex: Unexpected response: " <> T.pack (show val)
else throwM $ ElasticSearchException $ "esCheckIndex: Unexpected response:\n" <> (LB.toStrict $ encode val)
return $ Right $ IndexExists True

createElasticsearchIndex :: MonadIO m => MonadThrow m => ElasticSearchConfig -> Logger Text -> ChainwebVersion -> m HTTP.Request
Expand Down Expand Up @@ -773,7 +774,7 @@ realTransactions config (ChainwebHost h _p2p service) tcut tv distribution = do
logger' <- ask
retryResp <- retrying policy toRetry (const $ esCheckIndex (confManager cfg) logger' esConfig (nodeVersion config))
case retryResp of
Left err -> throwM $ ElasticSearchException $ T.pack err
Left err -> throwM $ ElasticSearchException $ fromString err
Right (IndexExists exists) ->
unless exists $ void $ retrying policy toRetry (const $ esPutReq (confManager cfg) logger' esConfig (nodeVersion config))
let act = loop (confirmationDepth config) tcut (liftIO randomEnum >>= generateTransactions False (verbose config))
Expand Down Expand Up @@ -877,7 +878,7 @@ realCoinTransactions config (ChainwebHost h _p2p service) tcut tv distribution =
logger' <- ask
retryResp <- retrying policy toRetry (const $ esCheckIndex (confManager cfg) logger' esConfig (nodeVersion config))
case retryResp of
Left err -> throwM $ ElasticSearchException $ T.pack err
Left err -> throwM $ ElasticSearchException $ fromString err
Right (IndexExists exists) ->
unless exists $ void $ retrying policy toRetry (const $ esPutReq (confManager cfg) logger' esConfig (nodeVersion config))
let act = loop (confirmationDepth config) tcut (generateTransactions True (verbose config) CoinContract)
Expand Down Expand Up @@ -922,7 +923,7 @@ simpleExpressions config (ChainwebHost h _p2p service) tcut tv distribution = do
logger' <- ask
retryResp <- retrying policy toRetry (const $ esCheckIndex (confManager gencfg) logger' esConfig (nodeVersion config))
case retryResp of
Left err -> throwM $ ElasticSearchException $ T.pack err
Left err -> throwM $ ElasticSearchException $ fromString err
Right (IndexExists exists) ->
unless exists $ void $ retrying policy toRetry (const $ esPutReq (confManager gencfg) logger' esConfig (nodeVersion config))
let chs = maybe (versionChains $ nodeVersion config) NES.fromList
Expand Down
2 changes: 1 addition & 1 deletion lib/TXG/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ unsafeManager :: IO Manager
unsafeManager = newTlsManagerWith
$ mkManagerSettings (TLSSettingsSimple True True True) Nothing

newtype ElasticSearchException = ElasticSearchException T.Text
newtype ElasticSearchException = ElasticSearchException B.ByteString
deriving (Show, Eq, Ord, IsString, Generic)

-- -------------------------------------------------------------------------- --
Expand Down

0 comments on commit ed3565b

Please sign in to comment.