public function dispatchError(\Zend\Mvc\MvcEvent $e)
    {
        $error = $e->getError();
        if (empty($error)) {
            return;
        }

        // Do nothing if the result is a response object
        $result = $e->getResult();
        if ($result instanceof \Zend\Stdlib\ResponseInterface) {
            return;
        }

        switch ($error) {
            case \Zend\Mvc\Application::ERROR_CONTROLLER_NOT_FOUND:
            case \Zend\Mvc\Application::ERROR_CONTROLLER_INVALID:
            case \Zend\Mvc\Application::ERROR_ROUTER_NO_MATCH:
            case 'error-route-unauthorized':
                // Specifically not handling these
                return;

            case \Zend\Mvc\Application::ERROR_EXCEPTION:
                $exception = $e->getParam('exception');
                if (!($exception instanceof \Exception)) {
                    return;
                }
                $msg = '';
                $prev = $exception->getPrevious();
                while ($prev !== null) {
                    $msg .= PHP_EOL.'Previous: '.$prev->getMessage().' in '.
                             $prev->getFile().' in line '.$prev->getLine().
                             '.';
                    $prev = $prev->getPrevious();
                }
                $this->log(ErrorLogger::ERR,
                        'Dispatch: '.$exception->getMessage().' in '.
                                 $exception->getFile().' in line '.
                                 $exception->getLine().'.'.$msg.PHP_EOL.
                                 'Trace:'.PHP_EOL.
                                 $exception->getTraceAsString());
                break;
            default:
                $this->log(ErrorLogger::ERR,
                'Erro desconhecido no dispatch: '.$error);
                break;

        }
    }