Skip to content

Commit

Permalink
Update exception
Browse files Browse the repository at this point in the history
  • Loading branch information
matrunchyk committed Apr 7, 2019
2 parents 373412c + 3b293a2 commit 4c6ba5b
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions src/ClamavValidator/ClamavValidatorException.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,41 @@
<?php namespace Sunspikes\ClamavValidator;

use Exception;
use Illuminate\Validation\ValidationException;

class ClamavValidatorException extends Exception
class ClamavValidatorException extends ValidationException
{
protected $exception;

public $attribute;

public function __construct(\Exception $exception, string $attribute, \Illuminate\Contracts\Validation\Validator $validator, $response = null)
{
$this->exception = $exception;
$this->attribute = $attribute;

parent::__construct($validator, $this->makeResponse());
}

public function makeResponse()
{
$message = $this->exception->getMessage();

if (substr_count($message, 'SOCKET_ECONNREFUSED')) {
$message = 'Unable to initiate antivirus check. Please try later.';
}

if (request()->expectsJson()) {
return response()->json([
'errors' => [
$this->attribute => $message
],
'message' => $message
], 422);
}

return redirect()->back()->withInput(
request()->input()
);
}
}

0 comments on commit 4c6ba5b

Please sign in to comment.