2017 © Pedro Peláez
 

symfony-bundle api-exception-bundle

catch all Symfony 3.3 or newer errors and convert it to problem json RFC7807 response

image

app-verk/api-exception-bundle

catch all Symfony 3.3 or newer errors and convert it to problem json RFC7807 response

  • Tuesday, June 26, 2018
  • by art4webs
  • Repository
  • 4 Watchers
  • 1 Stars
  • 141 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 5 Versions
  • 21 % Grown

The README.md

ApiExceptionBundle

Build Status, (*1)

Catch all Symfony 3.3 or newer errors and convert it to problem+json RFC7807 response, (*2)

Installation:

Required the bundle with composer:, (*3)

$ php composer.phar require app-verk/api-exception-bundle

Add bundle to AppKernel:, (*4)

<?php
    // app/AppKernel.php

    public function registerBundles()
    {
        $bundles = array(
            // ...

            new AppVerk\ApiExceptionBundle\AppVerkApiExceptionBundle(),
        );
    }

Configuration:

AppVerkApiProblemExceptionBundle automatically catch your errors by ApiExceptionSubscriber and return application/problem+json response:, (*5)

{
  "detail": "Description of problem",
  "status": 404,
  "type": "about:blank",
  "title": "Not Found"
}

changing data structure:

Bundle provide ResponseFactoryInterface for overriding response data, if u want change response data., (*6)

Example usage:

to receive response like:, (*7)

{
  "exception": {
      "detail": "Description of problem",
      "status": 404,
      "type": "about:blank",
      "title": "Not Found"
  }
}

create new CustomResponseFactory:, (*8)

<?php

...
class FBExceptionResponseFactory implements ResponseFactoryInterface
{
    public function createResponse(ApiProblemInterface $apiProblem)
    {
        $data = $apiProblem->ToArray();

        $response = new JsonResponse(
            $this->prepareData($data)
        );

        $response->headers->set('Content-Type', 'application/problem+json');

        return $response;
    }

    public function prepareData($data)
    {
        return [
            'exception' => [
                $data
            ],
        ];
    }
}

Config reference:

app_verk_api_exception:
    response_factory: AppVerk\ApiExceptionBundle\Factory\ApiProblemResponseFactory
    enabled: true
    paths_excluded: ['/admin/']

The Versions

26/06 2018

dev-master

9999999-dev

catch all Symfony 3.3 or newer errors and convert it to problem json RFC7807 response

  Sources   Download

MIT

The Requires

 

by Michał Jędraszczyk

api-problem api exceptions problem json

16/01 2018

v1.0.2

1.0.2.0

catch all Symfony 3.3 errors and convert it to problem json RFC7807 response

  Sources   Download

MIT

The Requires

 

by Michał Jędraszczyk

api-problem api exceptions problem json

18/10 2017

v1.0.1

1.0.1.0

catch all Symfony 3.3 errors and convert it to problem json RFC7807 response

  Sources   Download

MIT

The Requires

 

by Michał Jędraszczyk

api-problem api exceptions problem json

18/10 2017

dev-travis

dev-travis

catch all Symfony 3.3 errors and convert it to problem json RFC7807 response

  Sources   Download

MIT

The Requires

 

by Michał Jędraszczyk

api-problem api exceptions problem json

07/07 2017

v1.0

1.0.0.0

catch all Symfony 3.3 errors and convert it to problem json RFC7807 response

  Sources   Download

MIT

The Requires

 

by Michał Jędraszczyk

api-problem api exceptions problem json