@@ -35,37 +35,41 @@ import qualified Pipes.Prelude as P
3535-- TODO: remove this when the issue is fixed at Pursuit
3636queryPursuit :: Text -> IO ByteString
3737queryPursuit q = do
38- let qClean = T. dropWhileEnd (== ' .' ) q
39- req' <- parseRequest " http://pursuit.purescript.org/search"
40- let req = req'
41- { queryString= " q=" <> (fromString . T. unpack) qClean
42- , requestHeaders= [(hAccept, " application/json" )]
43- }
44- m <- newManager tlsManagerSettings
45- withHTTP req m $ \ resp ->
46- P. fold (<>) " " identity (responseBody resp)
38+ let qClean = T. dropWhileEnd (== ' .' ) q
39+ req' <- parseRequest " http://pursuit.purescript.org/search"
40+ let req = req'
41+ { queryString= " q=" <> (fromString . T. unpack) qClean
42+ , requestHeaders= [(hAccept, " application/json" )]
43+ }
44+ m <- newManager tlsManagerSettings
45+ withHTTP req m $ \ resp ->
46+ P. fold (<>) " " identity (responseBody resp)
47+
4748
4849handler :: HttpException -> IO [a ]
50+ handler StatusCodeException {} = pure []
4951handler _ = pure []
5052
5153searchPursuitForDeclarations :: Text -> IO [PursuitResponse ]
52- searchPursuitForDeclarations query = E. handle handler $ do
53- r <- queryPursuit query
54- let results' = decode (fromStrict r) :: Maybe Array
55- case results' of
56- Nothing -> pure []
57- Just results -> pure (mapMaybe (isDeclarationResponse . fromJSON) (toList results))
54+ searchPursuitForDeclarations query =
55+ (do r <- queryPursuit query
56+ let results' = decode (fromStrict r) :: Maybe Array
57+ case results' of
58+ Nothing -> pure []
59+ Just results -> pure (mapMaybe (isDeclarationResponse . fromJSON) (toList results))) `E.catch`
60+ handler
5861 where
5962 isDeclarationResponse (Success a@ DeclarationResponse {}) = Just a
6063 isDeclarationResponse _ = Nothing
6164
6265findPackagesForModuleIdent :: Text -> IO [PursuitResponse ]
63- findPackagesForModuleIdent query = E. handle handler $ do
64- r <- queryPursuit query
65- let results' = decode (fromStrict r) :: Maybe Array
66- case results' of
66+ findPackagesForModuleIdent query =
67+ ( do r <- queryPursuit query
68+ let results' = decode (fromStrict r) :: Maybe Array
69+ case results' of
6770 Nothing -> pure []
68- Just results -> pure (mapMaybe (isModuleResponse . fromJSON) (toList results))
71+ Just results -> pure (mapMaybe (isModuleResponse . fromJSON) (toList results))) `E.catch`
72+ handler
6973 where
7074 isModuleResponse (Success a@ ModuleResponse {}) = Just a
7175 isModuleResponse _ = Nothing
0 commit comments