git.iko.soy/typeable/bloodhound
on master help sign in
Change error parsing to support basic es20 error responses
commit0b810f0f10bbabde353b75cdfd0d5f61249d1fde authorAlistair Bush <alistair.bush@gmail.com> dateTue 23 Aug 2016, 00:36 (10 years ago) parent99987f7
2 files changed+11−3
src/Database/Bloodhound/Types.hs+1−1 tests/tests.hs+10−2
src/Database/Bloodhound/Types.hs+1−1
@@ -3261,7 +3261,7 @@ instance (FromJSON a) => FromJSON (EsResultFound a) where
32613261instance FromJSON EsError where
32623262 parseJSON (Object v) = EsError <$>
32633263 v .: "status" <*>
3264− v .: "error"
3264+ (v .: "error" <|> (v .: "error" >>= (.: "reason")))
32653265 parseJSON _ = empty
32663266
32673267instance FromJSON IndexAliasesSummary where
tests/tests.hs+10−2
@@ -96,6 +96,9 @@ es15 = Vers.Version [1, 5, 0] []
9696es16 :: Vers.Version
9797es16 = Vers.Version [1, 6, 0] []
9898
99+es20 :: Vers.Version
100+es20 = Vers.Version [2, 0, 0] []
101+
99102getServerVersion :: IO (Maybe Vers.Version)
100103getServerVersion = fmap extractVersion <$> withTestEnv getStatus
101104 where
@@ -885,12 +888,17 @@ main = hspec $ do
885888 validateStatus resp 200
886889 validateStatus deleteResp 200
887890
888− describe "error parsing" $ do
889− it "can parse EsErrors" $ withTestEnv $ do
891+ describe "error parsing" $ do
892+ it "can parse EsErrors for < 2.0" $ when' (atmost es16) $ withTestEnv $ do
890893 res <- getDocument (IndexName "bogus") (MappingName "also_bogus") (DocId "bogus_as_well")
891894 let errorResp = eitherDecode (responseBody res)
892895 liftIO (errorResp `shouldBe` Right (EsError 404 "IndexMissingException[[bogus] missing]"))
893896
897+ it "can parse EsErrors for >= 2.0" $ when' (atleast es20) $ withTestEnv $ do
898+ res <- getDocument (IndexName "bogus") (MappingName "also_bogus") (DocId "bogus_as_well")
899+ let errorResp = eitherDecode (responseBody res)
900+ liftIO (errorResp `shouldBe` Right (EsError 404 "no such index"))
901+
894902 describe "document API" $ do
895903 it "indexes, updates, gets, and then deletes the generated document" $ withTestEnv $ do
896904 _ <- insertData