Init
This commit is contained in:
26
app/Exceptions/ApiException.php
Normal file
26
app/Exceptions/ApiException.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Exception;
|
||||
use App\Responses\BaseResponse;
|
||||
|
||||
class ApiException extends Exception {
|
||||
|
||||
protected $message;
|
||||
protected $errorcode;
|
||||
|
||||
protected $code = 422;
|
||||
|
||||
public function __construct($code,$message) {
|
||||
$this->errorcode = $code;
|
||||
$this->message = $message;
|
||||
}
|
||||
|
||||
public function render() {
|
||||
$response = new BaseResponse();
|
||||
$response->setMessage($this->message);
|
||||
$response->setStatus($this->errorcode);
|
||||
return response()->json($response, $this->code);
|
||||
}
|
||||
}
|
||||
25
app/Exceptions/BaseException.php
Normal file
25
app/Exceptions/BaseException.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Contracts\Validation\Validator;
|
||||
use App\Responses\BaseResponse;
|
||||
|
||||
class BaseException extends Exception {
|
||||
|
||||
protected $validator;
|
||||
|
||||
protected $code = 422;
|
||||
|
||||
public function __construct(Validator $validator) {
|
||||
$this->validator = $validator;
|
||||
}
|
||||
|
||||
public function render() {
|
||||
$response = new BaseResponse();
|
||||
$response->setMessage($this->validator->errors()->first());
|
||||
$response->setStatus("KO");
|
||||
return response()->json($response, $this->code);
|
||||
}
|
||||
}
|
||||
30
app/Exceptions/Handler.php
Normal file
30
app/Exceptions/Handler.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||
use Throwable;
|
||||
|
||||
class Handler extends ExceptionHandler
|
||||
{
|
||||
/**
|
||||
* The list of the inputs that are never flashed to the session on validation exceptions.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $dontFlash = [
|
||||
'current_password',
|
||||
'password',
|
||||
'password_confirmation',
|
||||
];
|
||||
|
||||
/**
|
||||
* Register the exception handling callbacks for the application.
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
$this->reportable(function (Throwable $e) {
|
||||
//
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user