Custom Responses and Exceptions
Follow along to learn how to setup custom responses and exceptions.Table of Contents
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,
RESPONSE_CODE is your custom response code and
200 is the HTTP status code.
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.
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.