0

Im trying to make a little change in exception log and render in laravel 11.

I want to add an uuid to the errors.500 blade and log it right before the log, but i really dont know how to, laravel docs only shows how to customize custom exceptions, and google is focused on laravel 10 or older versions where error handling is very different.

I dont want to make custom exception, the web is used by thousands of users generating lots of logs, i need that uuid to trace an error when reported and be sure im seeing the right log line that triggers the error.

Can you help me with that?

2

1 Answer 1

0

I end up doing this. There has to be a better way but for now it appears to work.

Im waiting for it to implode the project in prod.

    ->withExceptions(function (Exceptions $exceptions) {
        $exceptions->report(function (Exception $e) {
            return false;
        });
        
        $exceptions->respond(function ($response, $e) {
            
            if ($e instanceof AuthenticationException) {
                return $response;
            } else {
                $hash = \Illuminate\Support\Str::uuid()->toString();
                Log::error($hash);
                Log::error($e);
                $message = $e->getMessage(); 
                return response()->view("errors.500", ["hash" => $hash,"message" => $message], 500);
            }
        });

Not the answer you're looking for? Browse other questions tagged or ask your own question.