protected function handleError(BadResponseException $e)
    {
        $request = $e->getRequest();
        $response = $e->getResponse();

        $level = floor($response->getStatusCode() / 100);

        if ($level == '4') {
            $label = 'Client error response';
        } elseif ($level == '5') {
            $label = 'Server error response';
        } else {
            $label = 'Unsuccessful response';
        }

        $message = $label .
            "\n [url] " . $request->getUri() .
            "\n [status code] " . $response->getStatusCode() .
            "\n [message] ";

        $body = $response->getBody();
        $json = json_decode($body, true);
        $message .= ($json != null && array_key_exists('message', $json)) ? $json['message'] : $body;

        if ($level == '4' && strpos($message, 'page with this title already exists') !== false) {
            return new DuplicateTitleException($message, 0, $e->getPrevious());
        }

        return new BadResponseException($message, $request, $response, $e->getPrevious());
    }