Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

284
Visualizações
Laravel custom error taking too long to response

Laravel Framework 8.48.0
PHP 7.4.18
Local Environment: Xampp, Windows10

I am developing RESTful API using Laravel 8. I have written some logic inside the register() method to make the error response better and more straightforward. Everything is working perfectly. But the problem is when Laravel detects an exception that doesn't fall any of this logic and APP_DEBUG=true, this piece of code start executing and takes too long to respond; it says execution timeout. If I clean the register() method, it shows an exception within 1 or 2 secs. What's wrong with my code?

I want a better and more precise error response + when APP_DEBUG=true quickly shows an error exception.

I think this is the culprit.

if (env('APP_DEBUG', false)) {
  return parent::render($request, $exception);
}

Handler.php

class Handler extends ExceptionHandler
{
    use ApiResponser;

    protected $dontReport = [
        //
    ];
    
    protected $dontFlash = [
        'password',
        'password_confirmation',
    ];
    
    public function register()
    {
        $this->renderable(function (Exception $exception, $request) {
            if ($request->wantsJson()) {

                if ($exception instanceof HttpException) {
                    $code = $exception->getStatusCode();
                    $message = Response::$statusTexts[$code];

                    return $this->errorResponse($message, $code);
                }

                if ($exception instanceof AuthenticationException) {
                    return $this->errorResponse($exception->getMessage(), Response::HTTP_UNAUTHORIZED);
                }

                if ($exception instanceof AuthorizationException) {
                    dd('authorization exception');
                    return $this->errorResponse($exception->getMessage(), Response::HTTP_FORBIDDEN);
                }

                if ($exception instanceof ValidationException) {
                    $errors = $exception->validator->errors()->getMessages();

                    return $this->errorResponse($errors, Response::HTTP_UNPROCESSABLE_ENTITY);
                }
                
                if (env('APP_DEBUG', false)) {
                    return parent::render($request, $exception);
                }

                return $this->errorResponse('Unexpected error occurred. Please contact your administrator for help.', Response::HTTP_INTERNAL_SERVER_ERROR);
            }
        });
    }
}
over 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda