# metricool/trunk/app/Exceptions/ValidationException.php

Metricool – Social media and site statistics, version trunk. 34 lines.

- Page: https://pluginprobe.com/plugins/metricool/trunk/code/app/Exceptions/ValidationException.php
- Raw: https://pluginprobe.com/plugins/metricool/trunk/raw/app/Exceptions/ValidationException.php
- Modified: 2026-08-20T14:08:30+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/metricool/trunk/code/app/Exceptions/ValidationException.php#L10-L20`.

```php
<?php

declare(strict_types=1);

namespace Metricool\Exceptions;

/**
 * Exception thrown when validation of request data fails.
 * @see \Metricool\Support\Validation\Validator
 */
class ValidationException extends RestDataException
{
    protected int $statusCode = 422;

    /**
     * Create a new instance with the given validation errors.
     */
    public static function withErrors(array $errors): self
    {
        $instance = new self(__('Validation failed.', 'metricool'));
        $instance->setData($errors);

        return $instance;
    }

    /**
     * Get the validation errors, keyed by field name.
     */
    public function errors(): array
    {
        return $this->getData();
    }
}

```
