2018-03-24 06:29:54 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Exceptions;
|
|
|
|
|
2019-08-21 20:17:44 +08:00
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
use Illuminate\Support\Facades\Validator;
|
2018-03-24 06:29:54 +08:00
|
|
|
use Illuminate\Validation\ValidationException;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show an internal error, bug piggyback off of the validation
|
|
|
|
* exception type - this has a place to show up in the UI as a
|
|
|
|
* flash message.
|
|
|
|
*/
|
|
|
|
class InternalError extends ValidationException
|
|
|
|
{
|
2018-03-31 00:08:53 +08:00
|
|
|
public const FIELD = 'internal_error_message';
|
|
|
|
public const MESSAGE = '';
|
2018-03-24 06:29:54 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* InternalError constructor.
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-03-24 06:29:54 +08:00
|
|
|
* @param string|null $message
|
|
|
|
* @param null $field
|
|
|
|
*/
|
2018-03-31 00:08:53 +08:00
|
|
|
public function __construct(string $message = null, $field = null)
|
2018-03-24 06:29:54 +08:00
|
|
|
{
|
|
|
|
Log::error($message);
|
|
|
|
$validator = Validator::make([], []);
|
2018-03-31 00:08:53 +08:00
|
|
|
$validator->errors()->add(
|
|
|
|
$field ?? static::FIELD,
|
2019-05-13 02:26:44 +08:00
|
|
|
$message ?? static::MESSAGE
|
|
|
|
);
|
2018-03-24 06:29:54 +08:00
|
|
|
|
|
|
|
parent::__construct($validator);
|
|
|
|
}
|
|
|
|
}
|