2017 © Pedro Peláez
 

library readable-api-error-response-bundle

image

zolfa/readable-api-error-response-bundle

  • Monday, June 20, 2016
  • by zolfa
  • Repository
  • 1 Watchers
  • 0 Stars
  • 105 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 1 % Grown

The README.md

This bundle is usually used in conjunction with the FOSRestBundle for returning readable exception messages., (*1)

By default, when a controller throws an exception, a response is returned with a status code of 500 and the content set to "internal error". The problem, however, is that exceptions you throw which contain helpful information are lost., (*2)

This means you have no way of providing useful error messages to developers who are going to use your API, and your UI application has no way of providing helpful messages to end users., (*3)

This bundle makes that as easy as a simple composer install and registration of the bundle in your AppKernel., (*4)

Installation

Step 1: Download the Bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:, (*5)

$ composer require azolf/readable-api-response-bundle

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation., (*6)

Step 2: Enable the Bundle

Then, enable the bundle by adding it to the list of registered bundles in the app/AppKernel.php file of your project:, (*7)

<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...

            new <vendor>\<bundle-name>\<bundle-long-name>(),
        );

        // ...
    }

    // ...
}

Usage

That's all you need to do to be able to return exceptions that make sense to both users and computers. To try out the bundle, add this to an action inside one of your controllers:, (*8)

    public function indexAction()
    {
        throw new \Exception('This is a test exception.');
    }

Now, open that page in your browser, and you must see a response like this:, (*9)

, (*10)

The Versions

20/06 2016

dev-master

9999999-dev

  Sources   Download

The Requires