git.iko.soy/typeable/bloodhound
on master help sign in
Merge pull request #132 from alistair/es20_error_responses

Beginnings of ES2 support - status page and error handling

commita0a33b882f163762a786273d43a03d7557a242a0 authorChris Allen <cma@bitemyapp.com> dateWed 24 Aug 2016, 10:42 (10 years ago) parent1467ffe0b810f0
2 files changed+12−4
src/Database/Bloodhound/Types.hs+2−2 tests/tests.hs+10−2
src/Database/Bloodhound/Types.hs+2−2
@@ -2990,7 +2990,7 @@ instance FromJSON MatchQueryType where
29902990instance FromJSON Status where
29912991 parseJSON (Object v) = Status <$>
29922992 v .:? "ok" <*>
2993− v .: "status" <*>
2993+ (v .:? "status" .!= 200) <*>
29942994 v .: "name" <*>
29952995 v .: "version" <*>
29962996 v .: "tagline"
@@ -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