This commit is contained in:
Gregory Letellier
2023-11-28 12:13:50 +01:00
commit d5b3ccabd9
537 changed files with 32146 additions and 0 deletions

View 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);
}
}

View 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);
}
}

View 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) {
//
});
}
}