1module Servant.Utils.Client where
3import Control.Applicative
4import Control.Exception
6import Control.Monad.IO.Class
7import Control.Monad.Trans.Either
9import Data.String.Conversions
10import Network.HTTP.Types
14import qualified Network.HTTP.Client as Client
16performRequest :: FromJSON result =>
17 Method -> Req -> Int -> URIAuth -> EitherT String IO result
18performRequest method req wantedStatus host = do
19 partialRequest <- liftIO $ reqToRequest req host
21 let request = partialRequest { Client.method = method
24 eResponse <- liftIO $ __withGlobalManager $ \ manager ->
25 catchStatusCodeException $
26 Client.httpLbs request manager
29 left (requestString ++ " failed with status: " ++ showStatus status)
32 let status = Client.responseStatus response
33 when (statusCode status /= wantedStatus) $
34 left (requestString ++ " failed with status: " ++ showStatus status)
35 result <- maybe (left (requestString ++ " returned invalid json")) return $
36 decode' (Client.responseBody response)
39 requestString = "HTTP " ++ cs method ++ " request"
40 showStatus (Status code message) =
41 show code ++ " - " ++ cs message
43catchStatusCodeException :: IO a -> IO (Either Status a)
44catchStatusCodeException action = catch (Right <$> action) $
46 Client.StatusCodeException status _ _ ->
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list