feat(purchase): implement InsufficientStockException for handling stock errors in checkout process
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
use App\Domains\Auth\Exceptions\AccountLockedException;
|
||||
use App\Domains\Ticket\Exceptions\TicketNotAvailableException;
|
||||
use App\Domains\Purchase\Exceptions\InsufficientStockException;
|
||||
use App\Http\Middleware\EnsureAdminAppTenant;
|
||||
use App\Http\Middleware\EnsureScannerTenant;
|
||||
use App\Http\Middleware\EnsureTenantHasMenu;
|
||||
@@ -74,6 +75,18 @@ return Application::configure(basePath: dirname(__DIR__))
|
||||
'message' => __('api.errors.forbidden'),
|
||||
], 403);
|
||||
});
|
||||
$exceptions->render(function (InsufficientStockException $exception, Request $request) {
|
||||
if (! $request->is('api/*')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'code' => 'purchase.insufficient_stock',
|
||||
'message' => $exception->getMessage(),
|
||||
'errors' => $exception->errors(),
|
||||
'unavailable_items' => $exception->unavailableItems,
|
||||
], 422);
|
||||
});
|
||||
$exceptions->render(function (ModelNotFoundException $exception, Request $request) {
|
||||
if (! $request->is('api/*')) {
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user