Added placeholder users; Better exception handling; Enhanced local setup

This commit is contained in:
Constantin Graf
2024-03-08 13:31:49 +01:00
parent 0ed5d14817
commit 77e7a63b83
38 changed files with 882 additions and 89 deletions

View File

@@ -0,0 +1,46 @@
<?php
declare(strict_types=1);
namespace App\Exceptions\Api;
use Exception;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use LogicException;
abstract class ApiException extends Exception
{
/**
* Render the exception into an HTTP response.
*/
public function render(Request $request): JsonResponse
{
return response()
->json([
'error' => true,
'key' => $this->getKey(),
'message' => $this->getTranslatedMessage(),
], 400);
}
/**
* Get the key for the exception.
*/
public function getKey(): string
{
if (defined(static::class.'::KEY')) {
return static::KEY;
}
throw new LogicException('API exceptions need the KEY constant defined.');
}
/**
* Get the translated message for the exception.
*/
public function getTranslatedMessage(): string
{
return __('exceptions.api.'.$this->getKey());
}
}

View File

@@ -0,0 +1,10 @@
<?php
declare(strict_types=1);
namespace App\Exceptions\Api;
class TimeEntryStillRunningApiException extends ApiException
{
const string KEY = 'time_entry_still_running';
}

View File

@@ -0,0 +1,10 @@
<?php
declare(strict_types=1);
namespace App\Exceptions\Api;
class UserNotPlaceholderApiException extends ApiException
{
const string KEY = 'user_not_placeholder';
}

View File

@@ -1,24 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Exceptions;
use Exception;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class ApiException extends Exception
{
/**
* Render the exception into an HTTP response.
*/
public function render(Request $request): JsonResponse
{
return response()
->json([
'error' => true,
'message' => $this->getMessage(),
], 400);
}
}

View File

@@ -1,9 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Exceptions;
class TimeEntryStillRunning extends ApiException
{
}