-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added socket failure exception formatting
- Loading branch information
1 parent
43e69db
commit 5488d37
Showing
3 changed files
with
37 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,37 @@ | ||
<?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([ | ||
$this->attribute => $message | ||
], 422); | ||
} | ||
|
||
return redirect()->back()->withInput( | ||
request()->input() | ||
); | ||
} | ||
} |