Reply: RESTful API error messages library that makes your life easier1 min read

When I started working with RESTful services in PHP, return API error messages to browser was always an issue, basically because must of the time you have to return the same error from different controllers, which leads to code duplication, error description differences and many other problems.

So I decided to create this Laravel package to make error handling as easy as possible.

Name: esdlabs/reply
Author: Victor Cruz
URL: https://github.com/esdlabs/reply

Features:

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

Installation:

Preparation:

Open your composer.json file and add the following to the require array:

Install dependencies

or

Integration:

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

In the $providers array add the following service provider for this package.

In the $aliases array add the following facade for this package.

Migrations

Database definition:

Table name: reply_errors

  • id
  • error_code
  • response_code
  • description

Define your errors at the errors table as follow:

id error_code response_ code description
1 0x001 401 Invalid username or password
2 0x002 406 Validation failed

Usage: