processResponse respond req = do res <- try req 
                                 case res of 
                                    Left ex -> processResponseEx ex
                                    Right clientResponse -> respond $ responseLBS
                                                                (Client.responseStatus clientResponse)
                                                                (fixResponseHeaders (Client.responseHeaders clientResponse))
                                                                (Client.responseBody clientResponse)
                                where processResponseEx (Client.StatusCodeException s hs _) = 
                                            case lookup "X-Response-Body-Start" hs of
                                                Just body -> respond $ responseLBS s (fixResponseHeaders hs) (fromStrict body)
                                                Nothing -> respond $ responseLBS s (fixResponseHeaders hs) ""
                                      processResponseEx (Client.FailedConnectionException host port)  = do 
                                                                Prelude.putStrLn ("Timeout while connecting to " ++ host ++ ":" ++ (show port))
                                                                respond $ responseLBS status502 [("Proxy-Agent","paranoia")] "Ohh nouz something went wrong"
                                      processResponseEx (Client.FailedConnectionException2 host port secure ex)  = do 
                                                                Prelude.putStrLn ("Failure while connecting to " ++ host ++ ":" ++ (show port) ++ " secure: "++(show secure) ++ "  "++(show ex)) 
                                                                respond $ responseLBS status502 [("Proxy-Agent","paranoia")] "Ohh nouz something went wrong"
                                      processResponseEx ex = do Prelude.putStrLn (show ex) 
                                                                respond $ responseLBS status502 [("Proxy-Agent","paranoia")] "Ohh nouz something went wrong"
processResponse respond req = do res <- try req 
                                 case res of 
                                    Left ex -> processResponseEx ex
                                    Right clientResponse -> respond $ responseLBS
                                                                (Client.responseStatus clientResponse)
                                                                (fixResponseHeaders (Client.responseHeaders clientResponse))
                                                                (Client.responseBody clientResponse)
                                where processResponseEx (Client.StatusCodeException s hs _) = 
                                            case lookup "X-Response-Body-Start" hs of
                                                Just body -> respond $ responseLBS s (fixResponseHeaders hs) (fromStrict body)
                                                Nothing -> respond $ responseLBS s (fixResponseHeaders hs) ""
                                      processResponseEx (Client.FailedConnectionException host port)  = do 
                                                                Prelude.putStrLn ("Timeout while connecting to " ++ host ++ ":" ++ (show port))
                                                                respond $ responseLBS status502 [("Proxy-Agent","paranoia")] "Ohh nouz something went wrong"
                                      processResponseEx (Client.FailedConnectionException2 host port secure ex)  = do 
                                                                Prelude.putStrLn ("Failure while connecting to " ++ host ++ ":" ++ (show port) ++ " secure: "++(show secure) ++ "  "++(show ex)) 
                                                                respond $ responseLBS status502 [("Proxy-Agent","paranoia")] "Ohh nouz something went wrong"
                                      processResponseEx ex = do Prelude.putStrLn (show ex) 
                                                                respond $ responseLBS status502 [("Proxy-Agent","paranoia")] "Ohh nouz something went wrong"
processResponse respond req = do res <- try req 
                                 case res of 
                                    Left ex -> processResponseEx ex
                                    Right clientResponse -> respond $ responseLBS
                                                                (Client.responseStatus clientResponse)
                                                                (fixResponseHeaders (Client.responseHeaders clientResponse))
                                                                (Client.responseBody clientResponse)
                                where processResponseEx (Client.StatusCodeException s hs _) = 
                                            case lookup "X-Response-Body-Start" hs of
                                                Just body -> respond $ responseLBS s (fixResponseHeaders hs) (fromStrict body)
                                                Nothing -> respond $ responseLBS s (fixResponseHeaders hs) ""
                                      processResponseEx (Client.FailedConnectionException host port)  = do 
                                                                Prelude.putStrLn ("Timeout while connecting to " ++ host ++ ":" ++ (show port))
                                                                respond $ responseLBS status502 [("Proxy-Agent","paranoia")] "Ohh nouz something went wrong"
                                      processResponseEx (Client.FailedConnectionException2 host port secure ex)  = do 
                                                                Prelude.putStrLn ("Failure while connecting to " ++ host ++ ":" ++ (show port) ++ " secure: "++(show secure) ++ "  "++(show ex)) 
                                                                respond $ responseLBS status502 [("Proxy-Agent","paranoia")] "Ohh nouz something went wrong"
                                      processResponseEx ex = do Prelude.putStrLn (show ex) 
                                                                respond $ responseLBS status502 [("Proxy-Agent","paranoia")] "Ohh nouz something went wrong"