Skip to content

Commit

Permalink
fix: EsError for OpenSearch
Browse files Browse the repository at this point in the history
  • Loading branch information
blackheaven committed Aug 15, 2024
1 parent fbb3cc4 commit 42167a4
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 8 deletions.
5 changes: 3 additions & 2 deletions bloodhound.cabal
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
cabal-version: 1.12

-- This file has been generated from package.yaml by hpack version 0.34.7.
-- This file has been generated from package.yaml by hpack version 0.36.1.
--
-- see: https://github.com/sol/hpack

name: bloodhound
version: 0.21.0.0
version: 0.22.0.0
synopsis: Elasticsearch client library for Haskell
description: Elasticsearch made awesome for Haskell hackers
category: Database, Search
Expand Down Expand Up @@ -47,6 +47,7 @@ library
Database.Bloodhound.Internal.Client.Doc
Database.Bloodhound.Internal.Count
Database.Bloodhound.Internal.PointInTime
X
Paths_bloodhound
hs-source-dirs:
src
Expand Down
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
0.22.0.0
========
- @blackheaven
- Fix `EsError` for OpenSearch

0.21.0.0
========
- @blackheaven
Expand Down
2 changes: 1 addition & 1 deletion package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: bloodhound
version: "0.21.0.0"
version: "0.22.0.0"
synopsis: Elasticsearch client library for Haskell
description: Elasticsearch made awesome for Haskell hackers
category: Database, Search
Expand Down
4 changes: 2 additions & 2 deletions src/Database/Bloodhound/Internal/Client/BHRequest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -261,15 +261,15 @@ instance (FromJSON a) => FromJSON (EsResultFound a) where
-- problem. If you can't parse the expected response, its a good idea to
-- try parsing this.
data EsError = EsError
{ errorStatus :: Int,
{ errorStatus :: Maybe Int,
errorMessage :: Text
}
deriving (Eq, Show)

instance FromJSON EsError where
parseJSON (Object v) =
EsError
<$> v .: "status"
<$> v .:? "status"
<*> (v .: "error" <|> (v .: "error" >>= (.: "reason")))
parseJSON _ = empty

Expand Down
2 changes: 1 addition & 1 deletion tests/Test/Import.hs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ grabFirst :: Either EsError (SearchResult a) -> Either EsError a
grabFirst r =
case fmap (hitSource . head . hits . searchHits) r of
(Left e) -> Left e
(Right Nothing) -> Left (EsError 500 "Source was missing")
(Right Nothing) -> Left (EsError (Just 500) "Source was missing")
(Right (Just x)) -> Right x

when' :: Monad m => m Bool -> m () -> m ()
Expand Down
2 changes: 1 addition & 1 deletion tests/Test/SourceFiltering.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ spec =
withTestEnv $
searchExpectSource
NoSource
(Left (EsError 500 "Source was missing"))
(Left (EsError (Just 500) "Source was missing"))

it "includes a source" $
withTestEnv $
Expand Down
2 changes: 1 addition & 1 deletion tests/tests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ main = hspec $ do
withTestEnv $ do
res <- getDocument @() (IndexName "bogus") (DocId "bogus_as_well")
errorResp <- parseEsResponse res
liftIO (errorResp `shouldBe` Left (EsError 404 "no such index [bogus]"))
liftIO (errorResp `shouldBe` Left (EsError (Just 404) "no such index [bogus]"))

describe "Monoid (SearchHits a)" $
prop "abides the monoid laws" $
Expand Down

0 comments on commit 42167a4

Please sign in to comment.