Zend Framework 2 Module that provides exception handling functionality

1.1.3 2014-12-30 05:27 UTC


Build Status

A simple zend framework 2 module to return exceptions as json in accordance with the application/api-problem+json standard.


Add the following to your composer root:

"require": {
    "zoopcommerce/maggott-module" : "~1.1"

Add the module to your application config:

'modules' => [


Any exceptions that you want returned as json need to be configured in the exception_map config key.


'zoop' => [
    'maggott' => [
        'exception_map' => [
            'Zoop\ShardModule\Exception\AccessControlException' => [
                'described_by' => 'access-control-exception',
                'title' => 'Access denied',
                'status_code' => 403,
                'extra_fields' => ['action'],
                'restricted_extra_fields' => ['documentClass']

The exception_map is an array of configured exceptions. The key for each item in the array must be the FQCN of the exception. All fields to configure an exception are optional. They are:


If this field is supplied, the returned exception will have a described_by field which points to a resource where more information about the exception can be found in human readable format.

If using the described_by field, you should also create a view model template called zoop/maggott/<described_by> that hold the extra human readable inforamtion.


The title of the exception


The http status code should the json response be set to. Defaults to 500, but also observes the status code in the response.


Other properties of the exception that should always be included in the json response.


Other properties of the exception that should only be included in the json response if displayExceptions is set to true.