class ErrorHandling implements ExtenderInterface

Methods

status(string $errorType, int $httpStatus)

<p>Define the corresponding HTTP status code for a well-known error type.</p>

type(string $exceptionClass, string $errorType)

<p>Define the internal error type for a specific exception class.</p>

handler(string $exceptionClass, string $handlerClass)

<p>Register a handler with custom error handling logic.</p>

reporter(string $reporterClass)

<p>Register an error reporter.</p>

extend(Container $container, Extension $extension = null)

No description

Details

status(string $errorType, int $httpStatus)

<p>Define the corresponding HTTP status code for a well-known error type.</p>

<p>This can be used to configure the status code (second parameter) to be used for the error response when encountering an exception with a certain type (first parameter). This type can be provided by the exception class itself (if it implements {\Flarum\Foundation\KnownError}), or explicitly defined by using the {\Flarum\Extend\type} method (useful for exception classes not under your control).</p>

Parameters

string $errorType
int $httpStatus

type(string $exceptionClass, string $errorType)

<p>Define the internal error type for a specific exception class.</p>

<p>If the exception class is under your control, you should prefer having the exception implement our {\Flarum\Foundation\KnownError} interface and define the type there. This method should only be used for third-party exceptions, e.g. when integrating another package that already defines its own exception classes.</p>

Parameters

string $exceptionClass
string $errorType

handler(string $exceptionClass, string $handlerClass)

<p>Register a handler with custom error handling logic.</p>

<p>When Flarum's default error handling is not enough for you, and the other methods of this extender don't help, this is the place where you can go wild! Using this method, you can define a handler class (second parameter) that will be responsible for exceptions of a certain type (first parameter).</p> <p>The handler class must implement a handle() method (surprise!), which returns a {\Flarum\Foundation\ErrorHandling\HandledError} instance. Besides the usual type and HTTP status code, such an object can also contain &quot;details&quot; - arbitrary data with more context for to the error.</p>

Parameters

string $exceptionClass
string $handlerClass

reporter(string $reporterClass)

<p>Register an error reporter.</p>

<p>Reporters will be called whenever Flarum encounters an exception that it does not know how to handle (i.e. none of the well-known exceptions that have an associated error type). They can then e.g. write the exception to a log, or send it to some external service, so that developers and/or administrators are notified about the error.</p> <p>When passing in a reporter class, make sure that it implements the {\Flarum\Foundation\ErrorHandling\Reporter} interface.</p>

Parameters

string $reporterClass

extend(Container $container, Extension $extension = null)

Parameters

Container $container
Extension $extension