class DefaultExceptionSubscriber extends DefaultExceptionSubscriber (View source)

internal  JSON:API maintains no PHP API. The API is the HTTP API. This class may change at any time and could break any dependencies on it.
 

Serializes exceptions in compliance with the JSON:API specification.

Properties

protected Serializer $serializer

The serializer.

from  DefaultExceptionSubscriber
protected array $serializerFormats

The available serialization formats.

from  DefaultExceptionSubscriber

Methods

array
getHandledFormats()

Specifies the request formats this subscriber will respond to.

static int
getPriority()

Specifies the priority of all listeners in this class.

onException(ExceptionEvent $event)

Handles errors for this subscriber.

static array
getSubscribedEvents()

Registers the methods in this class that should be listeners.

__construct(SerializerInterface $serializer, array $serializer_formats)

DefaultExceptionSubscriber constructor.

on4xx(ExceptionEvent $event)

Handles all 4xx errors for all serialization failures.

setEventResponse(ExceptionEvent $event, $status)

{@inheritdoc}

bool
isJsonApiExceptionEvent(ExceptionEvent $exception_event)

Check if the error should be formatted using JSON:API.

Details

protected array getHandledFormats()

Specifies the request formats this subscriber will respond to.

Return Value

array

An indexed array of the format machine names that this subscriber will attempt to process, such as "html" or "json". Returning an empty array will apply to all formats.

static protected int getPriority()

Specifies the priority of all listeners in this class.

The default priority is 1, which is very low. To have listeners that have a "first attempt" at handling exceptions return a higher priority.

Return Value

int

The event priority of this subscriber.

onException(ExceptionEvent $event)

Handles errors for this subscriber.

Parameters

ExceptionEvent $event

The event to process.

static array getSubscribedEvents()

Registers the methods in this class that should be listeners.

Return Value

array

An array of event listener definitions.

__construct(SerializerInterface $serializer, array $serializer_formats)

DefaultExceptionSubscriber constructor.

Parameters

SerializerInterface $serializer

The serializer service.

array $serializer_formats

The available serialization formats.

on4xx(ExceptionEvent $event)

Handles all 4xx errors for all serialization failures.

Parameters

ExceptionEvent $event

The event to process.

protected setEventResponse(ExceptionEvent $event, $status)

{@inheritdoc}

Parameters

ExceptionEvent $event
$status

protected bool isJsonApiExceptionEvent(ExceptionEvent $exception_event)

Check if the error should be formatted using JSON:API.

The JSON:API format is supported if the format is explicitly set or the request is for a known JSON:API route.

Parameters

ExceptionEvent $exception_event

The exception event.

Return Value

bool

TRUE if it needs to be formatted using JSON:API. FALSE otherwise.