<commit_before><?php
/**
 * Webiny Framework (http://www.webiny.com/framework)
 *
 * @copyright Copyright Webiny LTD
 */

namespace Webiny\Component\Rest;

use Webiny\Component\StdLib\Exception\ExceptionAbstract;

/**
 * RestErrorExceptions are thrown by the api service methods.
 * Implemented methods can throw this exception to notify the rest component that there has been an error.
 *
 * @package         Webiny\Component\Rest
 */
class RestErrorException extends ExceptionAbstract
{
    /**
     * @var string Error message.
     */
    protected $message = '';

    /**
     * @var string Error description.
     */
    protected $description = '';

    /**
     * @var string Error code.
     */
    protected $code = '';

    /**
     * @var int Http response code that should be send with the error. Default is 404.
     */
    protected $responseCode = 404;

    /**
     * @var array Additional error messages. Useful if you wish to return a validation error, this can be used to
     *            store errors per-field.
     */
    protected $errors = [];


    /**
     * Base constructor.
     *
     * @param string $message      Error message.
     * @param string $description  Error description.
     * @param string $code         Error code.
     * @param int    $responseCode Http response code that should be send with the error. Default is 404.
     */
    public function __construct($message, $description = '', $code = '', $responseCode = 404)
    {
        $this->message = $message;
        $this->description = $description;
        $this->code = $code;
    }

    /**
     * Add an additional error to the exception.
     *
     * @param array $error Addition error.
     */
    public function addError(array $error)
    {
        $this->errors[] = $error;
    }

    /**
     * Get the list of all additional errors.<commit_msg>Rest responseCode assignment in constructor<commit_after><?php
/**
 * Webiny Framework (http://www.webiny.com/framework)
 *
 * @copyright Copyright Webiny LTD
 */

namespace Webiny\Component\Rest;

use Webiny\Component\StdLib\Exception\ExceptionAbstract;

/**
 * RestErrorExceptions are thrown by the api service methods.
 * Implemented methods can throw this exception to notify the rest component that there has been an error.
 *
 * @package         Webiny\Component\Rest
 */
class RestErrorException extends ExceptionAbstract
{
    /**
     * @var string Error message.
     */
    protected $message = '';

    /**
     * @var string Error description.
     */
    protected $description = '';

    /**
     * @var string Error code.
     */
    protected $code = '';

    /**
     * @var int Http response code that should be send with the error. Default is 404.
     */
    protected $responseCode = 404;

    /**
     * @var array Additional error messages. Useful if you wish to return a validation error, this can be used to
     *            store errors per-field.
     */
    protected $errors = [];


    /**
     * Base constructor.
     *
     * @param string $message      Error message.
     * @param string $description  Error description.
     * @param string $code         Error code.
     * @param int    $responseCode Http response code that should be send with the error. Default is 404.
     */
    public function __construct($message, $description = '', $code = '', $responseCode = 404)
    {
        $this->message = $message;
        $this->description = $description;
        $this->code = $code;
        $this->responseCode = $responseCode;
    }

    /**
     * Add an additional error to the exception.
     *
     * @param array $error Addition error.
     */
    public function addError(array $error)
    {
        $this->errors[] = $error;
    }

    /**
     * Get the list of all additional errors.
{'fraction_non_alphanumeric': 0.10903344745851988, 'fraction_numerical': 0.006320779562812747, 'mean_word_length': 2.2713178294573644, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4548128', 'n_tokens_mistral': 1039, 'n_tokens_neox': 1008, 'n_words': 353}