Mejoras en la api
This commit is contained in:
25
backend/app/Exceptions/GenericException.php
Normal file
25
backend/app/Exceptions/GenericException.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class GenericException extends Exception {
|
||||
|
||||
protected $error;
|
||||
protected $message;
|
||||
protected $status;
|
||||
|
||||
public function __construct($error, $message, $status) {
|
||||
$this->error = $error;
|
||||
$this->message = $message;
|
||||
$this->status = $status;
|
||||
}
|
||||
|
||||
public function render($request) {
|
||||
return response()->json([
|
||||
'error' => $this->error
|
||||
'message' => $this->message
|
||||
], $status);
|
||||
}
|
||||
}
|
||||
21
backend/app/Exceptions/InvalidUuidException.php
Normal file
21
backend/app/Exceptions/InvalidUuidException.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class InvalidUuidException extends Exception {
|
||||
|
||||
protected $uuid;
|
||||
|
||||
public function __construct($uuid) {
|
||||
$this->uuid = $uuid;
|
||||
}
|
||||
|
||||
public function render($request) {
|
||||
return response()->json([
|
||||
'error' => 'invalid_uuid',
|
||||
'message' => 'El id ' . $this->uuid . ' no es un UUID valido'
|
||||
], 400);
|
||||
}
|
||||
}
|
||||
23
backend/app/Exceptions/ModelNotFoundException.php
Normal file
23
backend/app/Exceptions/ModelNotFoundException.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class ModelNotFoundException extends Exception {
|
||||
|
||||
protected $modelName;
|
||||
protected $id;
|
||||
|
||||
public function __construct($modelName, $id) {
|
||||
$this->modelName= $modelName;
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
public function render($request) {
|
||||
return response()->json([
|
||||
'error' => $this->modelName . '_not_found',
|
||||
'message' => 'El ' . $this->modelName . ' con id ' . $this->id . ' no existe'
|
||||
], 404);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user