Custom Responses and Exceptions


Follow along to learn how to setup custom responses and exceptions.

Table of Contents
  1. Custom Responses
  2. Using Custom Responses
  3. Throwing Custom Exceptions

Custom Responses

If you wish to create a custom response or exception code, you can use the provided config/customresponses.php file. Add the new array key value pair using the following example:

'RESPONSE_CODE' => 200,

where RESPONSE_CODE is your custom response code and 200 is the HTTP status code.

Using Custom Responses

You can use custom responses by using the provided Photon ResponseRepository like so:

return $this->responseRepository->make('RSVP_SUCCESS', $responseData, 'customresponses');

It's important to provide the name of the config php file, in this case 'customresponses' as the 3rd parameter.

Throwing Custom Exceptions

If you wish to throw a custom exception, a bit similar to returning a custom response, you can do e.g.

throw new \PhotonException('RESPONSE_NAME', $responseData, null, [], 'customresponses');

Again, it is important to provide the config file name as the 5th parameter.

Sign-up to stay informed about news and updates.