2017 © Pedro Peláez
 

library reply

Manage your RESTful errors easier than ever

image

esdlabs/reply

Manage your RESTful errors easier than ever

  • Friday, September 5, 2014
  • by mookofe
  • Repository
  • 4 Watchers
  • 3 Stars
  • 120 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 0 % Grown

The README.md

esdlabs/reply

Package that makes RESTful error handling easier than ever., (*1)

Features

  • Pre-defined errors and response codes
  • Run time errors response
  • Errors defined at database

Version

1.0.4, (*2)

Installation

Preparation, (*3)

Open your composer.json file and add the following to the require array:, (*4)

"esdlabs/reply": "1.*"

Install dependencies, (*5)

php composer install

Or, (*6)

php composer update

Integration

After installing the package, open your Laravel config file app/config/app.php and add the following lines., (*7)

In the $providers array add the following service provider for this package., (*8)

'Esdlabs\Reply\ReplyServiceProvider',

In the $aliases array add the following facade for this package., (*9)

'Reply' => 'Esdlabs\Reply\Facades\Reply',

Migrations, (*10)

php artisan migrate --package=esdlabs/reply

Database definition

reply_errors - id - error_code - response_code - description, (*11)

Define your errors at the errors table as follow:, (*12)

id error_code response_code description
1 '0x001' 400 'Invalid username or password'
2 '0x002' 406 ' Valitation failed

Usage

class LoginController extends Controller {

    public function store()
    {
        try
        {
            ...
        }
        catch (CustomException $e)
        {
            return Reply::error('0x001');
        }
        catch (AnotherException $e)
        {
            return Reply::error('0x002', array('note 1', 'note 2');
        }
        catch (Exception $e)
        {
            return Reply::customError('Custom error description', 500, "Note description");
        }
    }
}

HTTP Output

HTTP/1.1 400 Bad Request

{
    "error_code": "0x001",
    "description"": "Invalid username or password"
}

HTTP/1.1 406 Not Acceptable

{
    "error_code": "0x002",
    "description"": "Valitation failed",
    "notes" : [
        "note 1", 
        "note 2"
    ]
}

HTTP/1.1 500 Internal Server Error

{
    "error_code": "UNK-ERROR",
    "description"": "Custom error description",
    "notes": "Note description"
}

License

This package is open-sourced software licensed under the MIT license, (*13)

The Versions

05/09 2014

dev-master

9999999-dev

Manage your RESTful errors easier than ever

  Sources   Download

The Requires

 

by Victor Cruz

05/09 2014

v1.0.4

1.0.4.0

Manage your RESTful errors easier than ever

  Sources   Download

The Requires

 

by Victor Cruz

11/08 2014

v1.0.3

1.0.3.0

Manage your RESTful errors easier than ever

  Sources   Download

The Requires

 

by Victor Cruz

11/08 2014

v1.0.2

1.0.2.0

  Sources   Download

The Requires

 

by Victor Cruz

05/06 2014

v1.0.1

1.0.1.0

  Sources   Download

The Requires

 

by Victor Cruz

04/06 2014

v1.0.0

1.0.0.0

  Sources   Download

The Requires

 

by Edgar Nadal