@@ -639,19 +639,24 @@ existentialQuery url = do
639639-- categories. If they don't, a 'EsProtocolException' will be
640640-- thrown. If you encounter this, please report the full body it
641641-- reports along with your Elasticsearch verison.
642−parseEsResponse :: (MonadThrow m, FromJSON a) => Reply
642+parseEsResponse :: ( MonadThrow m
643+ , FromJSON a
644+ )
645+ => Reply
643646 -> m (Either EsError a)
644647parseEsResponse reply
645648 | respIsTwoHunna reply = case eitherDecode body of
646649 Right a -> return (Right a)
647− Left _ -> tryParseError
648− | otherwise = tryParseError
650+ Left err ->
651+ tryParseError err
652+ | otherwise = tryParseError "Non-200 status code"
649653 where body = responseBody reply
650− tryParseError = case eitherDecode body of
651− Right e -> return (Left e)
652− -- this case should not be possible
653− Left _ -> explode
654− explode = throwM (EsProtocolException body)
654+ tryParseError originalError
655+ = case eitherDecode body of
656+ Right e -> return (Left e)
657+ -- Failed to parse the error message.
658+ Left err -> explode ("Original error was: " <> originalError <> " Error parse failure was: " <> err)
659+ explode errorMsg = throwM (EsProtocolException (T.pack errorMsg) body)
655660
656661-- | 'indexExists' enables you to check if an index exists. Returns 'Bool'
657662-- in IO
@@ -711,16 +716,15 @@ listIndices =
711716 parse . responseBody =<< get =<< url
712717 where
713718 url = joinPath ["_cat/indices?format=json"]
714− parse body = maybe (throwM (EsProtocolException body)) return $ do
715− vals <- decode body
719+ parse body = either (\msg -> (throwM (EsProtocolException (T.pack msg) body))) return $ do
720+ vals <- eitherDecode body
716721 forM vals $ \val ->
717722 case val of
718− Object obj -> do
719− indexVal <- HM.lookup "index" obj
720− case indexVal of
721− String txt -> Just (IndexName txt)
722− _ -> Nothing
723− _ -> Nothing
723+ Object obj ->
724+ case HM.lookup "index" obj of
725+ (Just (String txt)) -> Right (IndexName txt)
726+ v -> Left $ "indexVal in listIndices failed on non-string, was: " <> show v
727+ v -> Left $ "One of the values parsed in listIndices wasn't an object, it was: " <> show v
724728
725729-- | 'updateIndexAliases' updates the server's index alias
726730-- table. Operations are atomic. Explained in further detail at