2017 © Pedro Peláez
 

library http-exception

An exception that contains http status code

image

majalin/http-exception

An exception that contains http status code

  • Friday, June 1, 2018
  • by MAJA-Lin
  • Repository
  • 1 Watchers
  • 0 Stars
  • 6 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 6 Versions
  • 0 % Grown

The README.md

PHP Exception with http status code

Build Status Coverage Status, (*1)

A exception that extends PHP exception and also contains http status code., (*2)

Now you can easily manage your error code and http status code together!, (*3)

Installation

composer require boltics\http-exception

Declaration

use Boltics\HttpException\Exception;
use Symfony\Component\HttpFoundation\Response;

Usage

$errorInfo = [
    'message' => 'Hola',
    'errorCode' => 1234,
    'httpCode' => Response::HTTP_BAD_REQUEST
];

throw new Exception($errorInfo);

// For Laravel Response
// You can use one exception to manage both error code and http code

class CustomizedException extends Exception
{
    const FIRST_ERROR = [
        'message' => 'Hola',
        'errorCode' => 1234,
        'httpCode' => Response::HTTP_BAD_REQUEST
    ];
}

try {
    // do something
    throw new CustomizedException(CustomizedException::FIRST_ERROR);
} catch (CustomizedException $e) {
    return $reponse()->json($data, $e->getHttpCode())
}


Documentation

  • __construct() The constructor checks that the value exist in the enum
  • getHttpCode() Returns http code
  • setHttpCode() Set http code
  • getErrorCode() Another approach to get exception code
  • setAdditionalData() Set additional data
  • getAdditionalData() Get additional data
  • appendAdditionalData() Append data to the additional data

Static methods:, (*4)

  • isValidHttpCode() method Returns boolean that http code is valid (in the supported list)
  • sanitizeException() method Returns valid exception info for __construct()

The Versions

01/06 2018

dev-develop

dev-develop https://github.com/MAJA-Lin/http-exception

An exception that contains http status code

  Sources   Download

MIT

The Requires

 

The Development Requires

exception type http-status-code http-code httpcode

01/06 2018

dev-master

9999999-dev https://github.com/MAJA-Lin/http-exception

An exception that contains http status code

  Sources   Download

MIT

The Requires

 

The Development Requires

exception type http-status-code http-code httpcode

01/06 2018

v1.1.1

1.1.1.0 https://github.com/MAJA-Lin/http-exception

An exception that contains http status code

  Sources   Download

MIT

The Requires

 

The Development Requires

exception type http-status-code http-code httpcode

01/06 2018

v1.1.0

1.1.0.0 https://github.com/MAJA-Lin/http-exception

An exception that contains http status code

  Sources   Download

MIT

The Requires

 

The Development Requires

exception type http-status-code http-code httpcode

09/11 2017

v1.0.1

1.0.1.0 https://github.com/MAJA-Lin/http-exception

An exception that contains http status code

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

exception type http-status-code http-code httpcode

09/11 2017

v1.0.0

1.0.0.0 https://github.com/MAJA-Lin/http-exception

An exception that contains http status code

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

exception type http-status-code http-code httpcode