doResponse :: Int -> Response BodyReader -> IO ()
doResponse reqNum response =
    catch (doResponse' >> printStatus) errHandler
  where
    printStatus :: IO ()
    printStatus = when (reqNum `mod` printStatusEvery == 0) $ print reqNum

    doResponse' :: IO ()
    doResponse' = withFile (outFilePath reqNum) WriteMode $ \fileHandle -> do
              let lazybody = responseBody response
              body <- brReadSome lazybody downloadLimitBytes
              ByteStringLazy.hPut fileHandle body
              ByteStringLazy.hPut fileHandle "\n"

    errHandler :: IOException -> IO ()
    errHandler err = writeFile (errFilePath reqNum) $ show err ++ "\n"
doResponse :: Int -> Response BodyReader -> IO ()
doResponse reqNum response =
    catch (doResponse' >> printStatus) errHandler
  where
    printStatus :: IO ()
    printStatus = when (reqNum `mod` printStatusEvery == 0) $ print reqNum

    doResponse' :: IO ()
    doResponse' = withFile (outFilePath reqNum) WriteMode $ \fileHandle -> do
              let lazybody = responseBody response
              body <- brReadSome lazybody downloadLimitBytes
              ByteStringLazy.hPut fileHandle body
              ByteStringLazy.hPut fileHandle "\n"

    errHandler :: IOException -> IO ()
    errHandler err = writeFile (errFilePath reqNum) $ show err ++ "\n"
doResponse reqNum response =
    catch (doResponse' >> printStatus) errHandler
  where
    printStatus :: IO ()
    printStatus = when (reqNum `mod` printStatusEvery == 0) $ print reqNum

    doResponse' :: IO ()
    doResponse' = withFile (outFilePath reqNum) WriteMode $ \fileHandle -> do
              let lazybody = responseBody response
              body <- brReadSome lazybody downloadLimitBytes
              ByteStringLazy.hPut fileHandle body
              ByteStringLazy.hPut fileHandle "\n"

    errHandler :: IOException -> IO ()
    errHandler err = writeFile (errFilePath reqNum) $ show err ++ "\n"