Open ecfxs opened 1 year ago
The quick fix for you is to edit App\Exceptions\Handler.php
Incase: You are not doing exception handling with Response Builder
See Exception Handling for reference for using Response Builder
exception handler.
/**
* Register the exception handling callbacks for the application.
*
* @return void
*/
public function register(): void
{
$this->renderable(function (Throwable $ex, $request) {
return ExceptionHandlerHelper::handle($ex, $request);
});
}
Next, update the register method as follows
/**
* Register the exception handling callbacks for the application.
*
* @return void
*/
public function register(): void
{
$this->renderable(function (\Throwable $ex, $request) {
$response = ExceptionHandlerHelper::render($request, $ex);
// Get response data from json response
$data = $response->getData(true);
// Modify the response format as needed
$date = new \DateTime();
$data['timezone'] = $date->getTimezone();
$data['timestamp'] = $date->getTimestamp();
// Update the json response with new data
$response->setData($data);
return $response;
});
}
Rendering the response using ExceptionHandlerHelper
followed by
modifying the rendered response data as necessary, and subsequently updating the response with the new data.
Steps to reproduce the behavior:
I defined a app/Http/Response/RB.php
And used ExceptionHandlerHelper How can I return the error message in the RB format I defined?
This is the default format
This is not the format I want
Thank you
Environment