Skip to content

tembra/jsonapi-errors-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

License Version Total Installs StyleCI

Description

JSON API logo

This framework agnostic package implements a simple and efficient way to throw or respond errors in JSON API specification version v1.0 as described in JSON API Errors. It also helps creating documentation for these errors on your application. It is based on 3rd party package neomerx/json-api that fully implements the JSON API Format.

It greatly simplifies the error processing with high code quality.

Still framework agnostic, you can easily integrate it with Laravel/Lumen and Dingo API.

Milestone to v1.0

  • Makes JSON API Errors as simple as calling a function
  • Standardize the errors
  • Provide most common error functions for HTTP Status Codes
  • Throw an exception or return the JSON string
  • Override JSON API Error Objects members
  • Support for Localization
  • Generate Documentation for Application Error Codes
  • Build PHPUnit tests

Sample usage

Assuming you don't want a specific class to standardize the errors and also don't want the documentation or localization, you can use as simple as this:

echo MyJsonApiErrors::badRequest([
  827 => [
    'title' => 'Another Error',
    'detail' => 'Detailed error description'
  ]
], false);

will output as string

{
  "errors": [
    {
      "status": "400",
      "code": "827",
      "title": "Another Error",
      "detail": "Detailed error description"
    }
  ]
}

The first parameter is an associative array where key is the error code in JSON API compliant format and value is another associative array where key/value pairs are some others members that JSON API Error Objects may have.

The second parameter false is to define whether a JsonApiException should be thrown or only the JSON string should be returned.

For more advanced usage please check out the Wiki.

Questions?

Do not hesitate to contact me on [email protected] or post an issue.

License

BSD 3-Clause. Please see License File for more information.

About

A PHP implementation of JSON API Errors compliant format.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages