<?php

namespace Opentalent\OtCore\Exception;

use Exception;

/**
 * Class ApiRequestException
 *
 * An ApiRequestException is raised when a request to the
 * Opentalent Api did not return a valid answer.
 *
 * @package Opentalent\OtCore\Exception
 */
class ApiRequestException extends Exception
{
    /**
     * ApiRequestException constructor.
     *
     * @param $message
     * @param int $code
     * @param Exception|null $previous
     */
    public function __construct($message, $code = 0, Exception $previous = null) {
        parent::__construct($message, $code, $previous);
    }

    /**
     * Construction from other exception
     *
     * @param Exception $e
     * @return ApiRequestException
     */
    public static function from_exception(Exception $e) {
        return new ApiRequestException($e->getMessage(), $e->getCode(), $e->getPrevious());
    }

}
