All Projects → middlewares → error-handler

middlewares / error-handler

Licence: MIT license
PSR-15 middleware to handle http errors

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to error-handler

React Native Exception Handler
A react native module that lets you to register a global error handler that can capture fatal/non fatal uncaught exceptions.
Stars: ✭ 1,170 (+8900%)
Mutual labels:  error
Nginx Error Pages
Cute Error Pages for your nginx web server
Stars: ✭ 166 (+1176.92%)
Mutual labels:  error
Failure
failure is a utility package for handling application errors.
Stars: ✭ 187 (+1338.46%)
Mutual labels:  error
Alloylever
1kb js library contains development debugging, error monitoring and reporting, user problem localization features - 1KB代码搞定开发调试发布,错误监控上报,用户问题定位
Stars: ✭ 1,348 (+10269.23%)
Mutual labels:  error
Ignition
A beautiful error page for Laravel apps
Stars: ✭ 1,885 (+14400%)
Mutual labels:  error
Graphql Errors
Simple error handler for GraphQL Ruby ❗️
Stars: ✭ 170 (+1207.69%)
Mutual labels:  error
Extensible Custom Error
JavaScript extensible custom error that can take a message and/or an Error object
Stars: ✭ 64 (+392.31%)
Mutual labels:  error
Node Common Errors
Common error classes and utility functions
Stars: ✭ 247 (+1800%)
Mutual labels:  error
Bugsnag Go
Automatic panic monitoring for Go and Go web frameworks, like negroni, gin, and revel
Stars: ✭ 155 (+1092.31%)
Mutual labels:  error
Statefulviewcontroller
Placeholder views based on content, loading, error or empty states
Stars: ✭ 2,139 (+16353.85%)
Mutual labels:  error
Didyoumean Python
Module to have suggestions in case of errors (NameError, AttributeError, etc).
Stars: ✭ 102 (+684.62%)
Mutual labels:  error
Errcheck
errcheck checks that you checked errors.
Stars: ✭ 1,763 (+13461.54%)
Mutual labels:  error
Afterqc
Automatic Filtering, Trimming, Error Removing and Quality Control for fastq data
Stars: ✭ 169 (+1200%)
Mutual labels:  error
Errors
Drop-in replacement for the standard library errors package and github.com/pkg/errors
Stars: ✭ 88 (+576.92%)
Mutual labels:  error
Emperror
The Emperor takes care of all errors personally
Stars: ✭ 201 (+1446.15%)
Mutual labels:  error
Seriouscode
This header file enforces Clang warnings to bu turned-on for specific flags (almost everyone, at least each one I was able to find).
Stars: ✭ 68 (+423.08%)
Mutual labels:  error
Kommander Ios
A lightweight, pure-Swift library for manage the task execution in different threads. Through the definition a simple but powerful concept, Kommand.
Stars: ✭ 167 (+1184.62%)
Mutual labels:  error
arm-hard-fault-handler
What to do when Hard fault hits? Debugger and error reporter solution for ARM Cortex M3 and M4.
Stars: ✭ 32 (+146.15%)
Mutual labels:  error
Human Signals
Human-friendly process signals
Stars: ✭ 223 (+1615.38%)
Mutual labels:  error
Swift Error Handler
Error handling library for Swift
Stars: ✭ 172 (+1223.08%)
Mutual labels:  error

middlewares/error-handler

Latest Version on Packagist Software License Testing Total Downloads

Middleware to catch and format errors encountered while handling the request.

Requirements

Installation

This package is installable and autoloadable via Composer as middlewares/error-handler.

composer require middlewares/error-handler

Example

use Middlewares\ErrorFormatter;
use Middlewares\ErrorHandler;
use Middlewares\Utils\Dispatcher;

// Create a new ErrorHandler instance
// Any number of formatters can be added. One will be picked based on the Accept
// header of the request. If no formatter matches, the first formatter in the array
// will be used.
$errorHandler = new ErrorHandler([
    new ErrorFormatter\HtmlFormatter(),
    new ErrorFormatter\ImageFormatter(),
    new ErrorFormatter\JsonFormatter(),
    new ErrorFormatter\PlainFormatter(),
    new ErrorFormatter\SvgFormatter(),
    new ErrorFormatter\XmlFormatter(),
]);

// ErrorHandler should always be the first middleware in the stack!
$dispatcher = new Dispatcher([
    $errorHandler,
    // ...
    function ($request) {
        throw HttpErrorException::create(404);
    }
]);

$request = $serverRequestFactory->createServerRequest('GET', '/');
$response = $dispatcher->dispatch($request);

Usage

Add the formatters to be used (instances of Middlewares\ErrorFormatter\FormatterInterface). If no formatters are provided, use all available.

$errorHandler = new ErrorHandler([
    new ErrorFormatter\HtmlFormatter(),
    new ErrorFormatter\JsonFormatter()
]);

Note: If no formatter is found, the first value of the array will be used. In the example above, HtmlFormatter.


Please see CHANGELOG for more information about recent changes and CONTRIBUTING for contributing details.

The MIT License (MIT). Please see LICENSE for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].