<commit_before><?php
/**
 * linkedin-client
 * Exception.php
 *
 * PHP Version 5
 *
 * @category Production
 * @package  Default
 * @author   <NAME> <<EMAIL>>
 * @date     8/17/17 23:11
 * @license  http://www.zoonman.com/projects/linkedin-client/license.txt linkedin-client License
 * @version  GIT: 1.0
 * @link     http://www.zoonman.com/projects/linkedin-client/
 */

namespace LinkedIn;

use GuzzleHttp\Exception\RequestException;

/**
 * Class Exception
 * @package LinkedIn
 */
class Exception extends \Exception
{
    /**
     * Error's description
     *
     * @var string
     */
    protected $description;

    /**
     * Exception constructor.
     * @param string $message
     * @param int $code
     * @param null $previousException
     * @param $description
     */
    public function __construct(
        $message = "",
        $code = 0,
        $previousException = null,
        $description = ''
    ) {
        parent::__construct($message, $code, $previousException);
        $this->description = $description;
    }

    /**
     * Get textual description that summarizes error.
     *
     * @return string
     */
    public function getDescription()
    {
        return $this->description;
    }

    /**
     * @param RequestException $exception
     *
     * @return self
     */
    public static function fromRequestException($exception)
    {
        return new static(
            $exception->getMessage(),
            $exception->getCode(),
            $exception,
            static::extractErrorDescription($exception)
        );
    }

    /**
     * @param RequestException $exception
     *
     * @return null|string
     */
    private static function extractErrorDescription($exception)
    {
        $json = Client::responseToArray(
            $exception->getResponse()
        );
        if (isset($json['error_description'])) {
            return $json['error_description'];
        } elseif (isset($json['message'])) {
            return $json['message'];
        } else {
            return null;
        }
    }
}<commit_msg>Fix getBody() on null error when $exception->getResponse() is null<commit_after><?php
/**
 * linkedin-client
 * Exception.php
 *
 * PHP Version 5
 *
 * @category Production
 * @package  Default
 * @author   <NAME> <<EMAIL>>
 * @date     8/17/17 23:11
 * @license  http://www.zoonman.com/projects/linkedin-client/license.txt linkedin-client License
 * @version  GIT: 1.0
 * @link     http://www.zoonman.com/projects/linkedin-client/
 */

namespace LinkedIn;

use GuzzleHttp\Exception\RequestException;

/**
 * Class Exception
 * @package LinkedIn
 */
class Exception extends \Exception
{
    /**
     * Error's description
     *
     * @var string
     */
    protected $description;

    /**
     * Exception constructor.
     * @param string $message
     * @param int $code
     * @param null $previousException
     * @param $description
     */
    public function __construct(
        $message = "",
        $code = 0,
        $previousException = null,
        $description = ''
    ) {
        parent::__construct($message, $code, $previousException);
        $this->description = $description;
    }

    /**
     * Get textual description that summarizes error.
     *
     * @return string
     */
    public function getDescription()
    {
        return $this->description;
    }

    /**
     * @param RequestException $exception
     *
     * @return self
     */
    public static function fromRequestException($exception)
    {
        return new static(
            $exception->getMessage(),
            $exception->getCode(),
            $exception,
            static::extractErrorDescription($exception)
        );
    }

    /**
     * @param RequestException $exception
     *
     * @return null|string
     */
    private static function extractErrorDescription($exception)
    {
        if ($exception->getResponse()) {
            $json = Client::responseToArray(
                $exception->getResponse()
            );
            if (isset($json['error_description'])) {
                return $json['error_description'];
            } elseif (isset($json['message'])) {
                return $json['message'];
            }
        }

        return null;
    }
}
{'fraction_non_alphanumeric': 0.1272812353766963, 'fraction_numerical': 0.006083294337856809, 'mean_word_length': 2.0601288475304225, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6493259', 'n_tokens_mistral': 1180, 'n_tokens_neox': 1144, 'n_words': 253}