      return $ case m_outPath of
        Nothing -> Left noOutErr
        Just outPath -> Right $ unpack outPath
  where
    opts = defaults & header "Accept" .~ ["application/json"]
                    & auth .~ m_creds
    noOutErr =
      "Latest build of job " ++ uri
                             ++ " has no output named 'out'."
    latestUri = uri ++ "/latest"

    isTransientError e = case e of
      InvalidUrlException _ _ -> Nothing
      _ -> Just e
