29 lines
667 B
Haskell
29 lines
667 B
Haskell
|
module Request where
|
||
|
|
||
|
import Data.Aeson
|
||
|
import Network.HTTP.Req
|
||
|
|
||
|
type Request = Req
|
||
|
|
||
|
runRequest :: Request a -> IO a
|
||
|
runRequest = runReq (defaultHttpConfig {httpConfigCheckResponse = \_ _ _ -> Nothing})
|
||
|
|
||
|
type URL = Url 'Https
|
||
|
|
||
|
data Error
|
||
|
= NotFound
|
||
|
| BadAuth ByteString
|
||
|
| ParseError String
|
||
|
|
||
|
type Action a = Request (Either Error a)
|
||
|
|
||
|
get :: URL -> Action Value
|
||
|
get url = do
|
||
|
response <- req GET url NoReqBody jsonResponse userAgent
|
||
|
pure case responseStatusCode response of
|
||
|
404 -> Left NotFound
|
||
|
403 -> Left (BadAuth (responseStatusMessage response))
|
||
|
_ -> Right (responseBody response)
|
||
|
where
|
||
|
userAgent = header "User-Agent" "migrate-to-gitea"
|