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