Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

287
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!