UnexpectedErrorStatus

Since v1.0.0

Description

UnexpectedErrorStatus is a HttpStatus value object. It represents the HTTP 500 Unexpected Error status.

"Unexpected Error" is a non-standard response phrase for the HTTP 500 status. We've added it for CLI apps to use. We think "Internal Server Error" is an odd thing for a CLI app to say.

Public Interface

UnexpectedErrorStatus has the following public interface:

// UnexpectedErrorStatus lives in this namespace
namespace GanbaroDigital\HttpStatus\StatusValues\RuntimeError;

// our base classes and interfaces
use GanbaroDigital\HttpStatus\Interfaces\HttpRuntimeErrorStatus;
use GanbaroDigital\HttpStatus\Interfaces\HttpStatus;
use GanbaroDigital\HttpStatus\StatusValues\HttpStatusObject;

class UnexpectedErrorStatus
  extends HttpStatus
  implements HttpStatus, HttpRuntimeErrorStatus
{
    /**
     * our constructor
     */
    public function __construct();

    /**
     * returns the HTTP status code
     *
     * @return int
     */
    public function getStatusCode();

    /**
     * returns the HTTP status reason-phrase
     *
     * @return string
     */
    public function getReasonPhrase();

    /**
     * returns the HTTP status line
     *
     * this is code + ' ' + reason-phrase
     *
     * @return string
     */
    public function getStatusLine();
}

How To Use

Construction

The constructor for UnexpectedErrorStatus takes no parameters.

use GanbaroDigital\HttpStatus\StatusValues\RuntimeError\UnexpectedErrorStatus;

$httpStatus = new UnexpectedErrorStatus;

getStatusCode()

UnexpectedErrorStatus::getStatusCode() returns the HTTP status code as an integer:

use GanbaroDigital\HttpStatus\StatusValues\RuntimeError\UnexpectedErrorStatus;

$httpStatus = new UnexpectedErrorStatus;
$statusCode = $httpStatus->getStatusCode();

// $statusCode contains the value '500' as an integer

HTTP status codes are part of the HTTP standards. Servers, proxies and clients use these codes to understand what happened with a HTTP request.

getReasonPhrase()

UnexpectedErrorStatus::getReasonPhrase() returns the HTTP reason phrase as a string:

use GanbaroDigital\HttpStatus\StatusValues\RuntimeError\UnexpectedErrorStatus;

$httpStatus = new UnexpectedErrorStatus;
$reasonPhrase = $httpStatus->getReasonPhrase();

// $reasonPhrase contains the value 'Unexpected Error' as a string

HTTP reason phrases are part of the HTTP standards. They're RuntimeError, and are there for humans to read. Servers, proxies and clients may store, forward and log these reason phrases, but they should never actually parse them or use them to understand what happened with a HTTP request.

getStatusLine()

UnexpectedErrorStatus::getStatusLine() returns the HTTP status line. This is the string that is printed after the HTTP protocol version at the start of any HTTP response.

use GanbaroDigital\HttpStatus\StatusValues\RuntimeError\UnexpectedErrorStatus;

$httpStatus = new UnexpectedErrorStatus;
$statusLine = $httpStatus->getStatusLine();

// $statusLine contains the value "500 Unexpected Error" as a string

// use $statusLine to set the response from your PHP app
header($_SERVER["SERVER_PROTOCOL"] ." " . $statusLine);

Class Contract

Here is the contract for this class:

GanbaroDigital\HttpStatus\StatusValues\RuntimeError\UnexpectedErrorStatus
 [x] Can instantiate
 [x] Is http status
 [x] Is http runtime error status
 [x] Has status code 500
 [x] Has correct reason phrase
 [x] Has correct status line

Class contracts are built from this class's unit tests.

Future releases of this class will not break this contract.

Future releases of this class may add to this contract. New additions may include:

  • clarifying existing behaviour (e.g. stricter contract around input or return types)
  • add new behaviours (e.g. extra class methods)

When you use this class, you can only rely on the behaviours documented by this contract.

If you:

  • find other ways to use this class,
  • or depend on behaviours that are not covered by a unit test,
  • or depend on undocumented internal states of this class,

... your code may not work in the future.

Notes

None at this time.

See Also