Giter Site home page Giter Site logo

whoops's Introduction

middlewares/whoops

Latest Version on Packagist Software License Testing Total Downloads

Middleware to use Whoops as error handler.

Requirements

Installation

This package is installable and autoloadable via Composer as middlewares/whoops.

composer require middlewares/whoops

Example

$dispatcher = new Dispatcher([
    new Middlewares\Whoops()
]);

$response = $dispatcher->dispatch(new ServerRequest());

Usage

The constructor accepts a Whoops\Run instance but creates one automatically if it's not provided. Optionally, you can provide a Psr\Http\Message\ResponseFactoryInterface as the second argument to create the response. If it's not defined, Middleware\Utils\Factory will be used to detect it automatically.

$whoops = new Whoops\Run();
$responseFactory = new MyOwnResponseFactory();

//Create a Run instance automatically
$middleware = new Middlewares\Whoops();

//Pass your own Run instance
$middleware = new Middlewares\Whoops($whoops);

//Pass a Run instance and ResponseFactory
$middleware = new Middlewares\Whoops($whoops, $responseFactory);

catchErrors

To catch not only throwable exceptions, but also php errors. This makes whoops to be registered temporary in order to capture the errors using set_error_handler. It's enabled by default so, to disable it you have to use ->catchErrors(false);

//Do not catch errors
$middleware = (new Middlewares\Whoops())->catchErrors(false);

handlerContainer

This option allows to define a custom PSR-11 container used to create the intance of Whoops\Handler\HandlerInterface based in the Accept header in the request.


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

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

whoops's People

Contributors

ajgarlag avatar arokettu avatar desumasuku avatar duncan3dc avatar oscarotero avatar reisraff avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

whoops's Issues

Support PHP 8

Tests almost pass, there is one problem with the test itself:

$this->assertNotFalse(strpos((string) $response->getBody(), 'Undefined variable: b'));

The message has changed and now contains dollar sign: PHP Warning: Undefined variable $b

Obvious blocker as I understand: middlewares/utils#22

Fatal errors result in an empty 500 response

With this middleware enabled any E_ERROR that is triggered during inner middleware execution will result in a HTTP 500 with an empty body.

This is because Whoops uses an output buffer to render fatal errors as part of the shutdown handler, and this middleware throws away the output buffer that contains the error message.

I tried numerous things to work around this but couldn't come up with a good way to do it in PHP <7.0. I don't really expect this issue to be resolved but I did want it documented.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.