Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

289
Vistas
in PHP, which Exception codes are mapped to http status codes?

I'm developing a (CakePHP) web application, thereby creating own exception classes.

At the moment I try to create a locked exception, that shall return HTTP status code 423 (Locked):

<?php
namespace App\Exceptions;

use Cake\Network\Exception\HttpException;

class MeasuringPointLockedException extends HttpException{   
    /**
     * Constructor
     *
     * @param string $message If no message is given 'Locked' will be the message
     */
    public function __construct($message = 'Locked'){   
        parent::__construct($message, 422);
    }
}    
?>

Unfortunately, at some point my code 423 is consumed and replaced by 500 (internal server error). I noticed, that only some codes are replaced, others (like 400, 404, 422) are passed through.

Note: HttpException is an extension of PHP builtin exception.

In between, I noticed, that response code 423 is intended for WebDAV services, but:

Is there any documentation, which codes are passed through? How could I achieve a status = 423 upon throwing (and not catching) such an exception?

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You can seen a bunch of http exceptions in here: [https://book.cakephp.org/3/en/development/errors.html1

Here is also a good example of how to make this implementation:

use Cake\Core\Exception\Exception;

class MissingWidgetException extends Exception
{
    // Set your message here
    protected $_messageTemplate = 'Your message';

    // Set your status code here
    protected $_defaultCode = 404;
}

throw new MissingWidgetException(['widget' => 'Pointy']);
about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda