@@ -61,6 +61,7 @@ module Database.Bloodhound.Types
6161 , Reply
6262 , EsResult(..)
6363 , EsResultFound(..)
64+ , EsError(..)
6465 , DocVersion
6566 , ExternalDocVersion(..)
6667 , VersionControl(..)
@@ -416,13 +417,18 @@ data EsResult a = EsResult { _index :: Text
416417 , _id :: Text
417418 , foundResult :: Maybe (EsResultFound a)} deriving (Eq, Show)
418419
419−
420420{-| 'EsResultFound' contains the document and its metadata inside of an
421421 'EsResult' when the document was successfully found.
422422-}
423423data EsResultFound a = EsResultFound { _version :: DocVersion
424424 , _source :: a } deriving (Eq, Show)
425425
426+{-| 'EsError' is the generic type that will be returned when there was a
427+ problem. If you can't parse the expected response, its a good idea to
428+ try parsing this.
429+-}
430+data EsError = EsError { errorStatus :: Int
431+ , errorMessage :: Text } deriving (Eq, Show)
426432
427433
428434{-| 'DocVersion' is an integer version number for a document between 1
@@ -2133,6 +2139,12 @@ instance (FromJSON a) => FromJSON (EsResultFound a) where
21332139 v .: "_source"
21342140 parseJSON _ = empty
21352141
2142+instance FromJSON EsError where
2143+ parseJSON (Object v) = EsError <$>
2144+ v .: "status" <*>
2145+ v .: "error"
2146+ parseJSON _ = empty
2147+
21362148instance ToJSON Search where
21372149 toJSON (Search query sFilter sort searchAggs highlight sTrackSortScores sFrom sSize _ sFields sSource) =
21382150 omitNulls [ "query" .= query