request
  :: (MonadIO m, MonadThrow m, ToJSON a, FromJSON b)
  => String
  -> a
  -> m (Either Error b)
request req r = do
  let
    setRequest =
      setRequestBodyJSON r . setRequestHeaders headers
  response <- httpLBS =<< fmap setRequest (parseRequest req)
  case Aeson.decode (getResponseBody response) of
    Just authResponse ->
      pure (Right authResponse)
    Nothing ->
      pure (Left (Error.fromResponse response))
request
  :: (MonadIO m, MonadThrow m, ToJSON a, FromJSON b)
  => String
  -> a
  -> m (Either Error b)
request req r = do
  let
    setRequest =
      setRequestBodyJSON r . setRequestHeaders headers
  response <- httpLBS =<< fmap setRequest (parseRequest req)
  case Aeson.decode (getResponseBody response) of
    Just authResponse ->
      pure (Right authResponse)
    Nothing ->
      pure (Left (Error.fromResponse response))
request req r = do
  let
    setRequest =
      setRequestBodyJSON r . setRequestHeaders headers
  response <- httpLBS =<< fmap setRequest (parseRequest req)
  case Aeson.decode (getResponseBody response) of
    Just authResponse ->
      pure (Right authResponse)
    Nothing ->
      pure (Left (Error.fromResponse response))