@@ -35,37 +35,41 @@ import qualified Pipes.Prelude as P
35-- TODO: remove this when the issue is fixed at Pursuit
35-- TODO: remove this when the issue is fixed at Pursuit
36queryPursuit :: Text -> IO ByteString
36queryPursuit :: Text -> IO ByteString
37queryPursuit q = do
37queryPursuit q = do
38− let qClean = T.dropWhileEnd (== '.') q
38+ let qClean = T.dropWhileEnd (== '.') q
39− req' <- parseRequest "http://pursuit.purescript.org/search"
39+ req' <- parseRequest "http://pursuit.purescript.org/search"
40− let req = req'
40+ let req = req'
41− { queryString= "q=" <> (fromString . T.unpack) qClean
41+ { queryString= "q=" <> (fromString . T.unpack) qClean
42− , requestHeaders=[(hAccept, "application/json")]
42+ , requestHeaders=[(hAccept, "application/json")]
44− m <- newManager tlsManagerSettings
44+ m <- newManager tlsManagerSettings
45− withHTTP req m $ \resp ->
45+ withHTTP req m $ \resp ->
46− P.fold (<>) "" identity (responseBody resp)
46+ P.fold (<>) "" identity (responseBody resp)
48handler :: HttpException -> IO [a]
49handler :: HttpException -> IO [a]
50+handler StatusCodeException{} = pure []
49handler _ = pure []
51handler _ = pure []
51searchPursuitForDeclarations :: Text -> IO [PursuitResponse]
53searchPursuitForDeclarations :: Text -> IO [PursuitResponse]
52−searchPursuitForDeclarations query = E.handle handler $ do
54+searchPursuitForDeclarations query =
53− r <- queryPursuit query
55+ (do r <- queryPursuit query
54− let results' = decode (fromStrict r) :: Maybe Array
56+ let results' = decode (fromStrict r) :: Maybe Array
55− case results' of
57+ case results' of
56− Nothing -> pure []
58+ Nothing -> pure []
57− Just results -> pure (mapMaybe (isDeclarationResponse . fromJSON) (toList results))
59+ Just results -> pure (mapMaybe (isDeclarationResponse . fromJSON) (toList results))) `E.catch`
59 isDeclarationResponse (Success a@DeclarationResponse{}) = Just a
62 isDeclarationResponse (Success a@DeclarationResponse{}) = Just a
60 isDeclarationResponse _ = Nothing
63 isDeclarationResponse _ = Nothing
62findPackagesForModuleIdent :: Text -> IO [PursuitResponse]
65findPackagesForModuleIdent :: Text -> IO [PursuitResponse]
63−findPackagesForModuleIdent query = E.handle handler $ do
66+findPackagesForModuleIdent query =
64− r <- queryPursuit query
67+ (do r <- queryPursuit query
65− let results' = decode (fromStrict r) :: Maybe Array
68+ let results' = decode (fromStrict r) :: Maybe Array
66− case results' of
69+ case results' of
67 Nothing -> pure []
70 Nothing -> pure []
68− Just results -> pure (mapMaybe (isModuleResponse . fromJSON) (toList results))
71+ Just results -> pure (mapMaybe (isModuleResponse . fromJSON) (toList results))) `E.catch`
70 isModuleResponse (Success a@ModuleResponse{}) = Just a
74 isModuleResponse (Success a@ModuleResponse{}) = Just a
71 isModuleResponse _ = Nothing
75 isModuleResponse _ = Nothing