-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Description
What needs to be done?
Modify the initialization process by editing the bootstrap/app.php
file. Specifically, inside the withExceptions
call, add the following logic only if it has not already been added:
$exceptions->render(function (HttpException $exception, Request $request) { return ($request->expectsJson()) ? response()->json(['error' => $exception->getMessage()], $exception->getStatusCode()) : null; });
This requires:
Detecting if this exception rendering logic is already registered to avoid duplicate calls.
Adding the logic conditionally only if it is not present.
Ensuring that the logic integrates smoothly with existing code in the
bootstrap/app.php
.
Expected Outcome
What is the expected result?
The
withExceptions
call inbootstrap/app.php
should include the new rendering logic only once.When a
HttpException
occurs and the request expects JSON, a JSON response with the error message and status code is returned.No duplicate handlers or conflicts occur if the initialization runs multiple times.
Verification Scenarios
How can this be tested?
Run the initialization process when the logic is not present; verify that the new exception rendering logic is added to
bootstrap/app.php
.Run the initialization process again; verify that the logic is not duplicated.
Trigger an HTTP exception with a request that expects JSON and verify the response is JSON formatted with the error message and status code.
Trigger an HTTP exception with a request that does not expect JSON and verify the handler returns
null
(allowing normal exception handling).Review the
bootstrap/app.php
file to ensure no duplicate exception handlers are present.Confirm no errors or debug information appear in the application logs or console.