{"id":19594426,"url":"https://github.com/swoft-cloud/swoft-whoops","last_synced_at":"2025-04-27T15:33:53.490Z","repository":{"id":57063279,"uuid":"125233395","full_name":"swoft-cloud/swoft-whoops","owner":"swoft-cloud","description":"[READ ONLY] Swoft errors for cool kids by filp/whoops","archived":false,"fork":false,"pushed_at":"2021-05-07T16:53:03.000Z","size":21,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-19T17:53:57.623Z","etag":null,"topics":["swoft","swoft-component","swoft-errors","swoft-whoops"],"latest_commit_sha":null,"homepage":"https://www.swoft.org","language":"PHP","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/swoft-cloud.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-03-14T15:23:56.000Z","updated_at":"2024-12-16T05:58:15.000Z","dependencies_parsed_at":"2022-08-24T10:10:11.754Z","dependency_job_id":null,"html_url":"https://github.com/swoft-cloud/swoft-whoops","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swoft-cloud%2Fswoft-whoops","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swoft-cloud%2Fswoft-whoops/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swoft-cloud%2Fswoft-whoops/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swoft-cloud%2Fswoft-whoops/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/swoft-cloud","download_url":"https://codeload.github.com/swoft-cloud/swoft-whoops/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251162822,"owners_count":21545827,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["swoft","swoft-component","swoft-errors","swoft-whoops"],"created_at":"2024-11-11T08:43:30.827Z","updated_at":"2025-04-27T15:33:48.463Z","avatar_url":"https://github.com/swoft-cloud.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Swoft Whoops\n\n[![Latest Stable Version](http://img.shields.io/packagist/v/swoft/whoops.svg)](https://packagist.org/packages/swoft/whoops)\n[![Php Version](https://img.shields.io/badge/php-%3E=7.1-brightgreen.svg?maxAge=2592000)](https://secure.php.net/)\n[![Swoft Doc](https://img.shields.io/badge/docs-passing-green.svg?maxAge=2592000)](https://www.swoft.org/docs)\n[![Swoft License](https://img.shields.io/hexpm/l/plug.svg?maxAge=2592000)](https://github.com/swoft-cloud/swoft/blob/master/LICENSE)\n\nSwoft http errors for cool kids by [filp/whoops](https://github.com/filp/whoops)\n\n## Install\n\n- composer command\n\n```bash\ncomposer require --dev swoft/whoops\n```\n\n## Usage\n\n- Method 1\n\nUse the `Swoft\\Whoops\\WhoopsMiddleware` as an global middleware(`app/bean.php`):\n\n```php\n    'httpDispatcher'   =\u003e [\n        // Add global http middleware\n        'middlewares' =\u003e [\n            // Notice: Please add to the first place\n            \\Swoft\\Whoops\\WhoopsMiddleware::class,\n        ],\n    ],\n```\n\n- Method 2\n\nChange the `App\\Exception\\Handler\\HttpExceptionHandler` class:\n\n```php\n\u003c?php declare(strict_types=1);\n\nnamespace App\\Exception\\Handler;\n\nuse Swoft\\Error\\Annotation\\Mapping\\ExceptionHandler;\nuse Swoft\\Http\\Message\\ContentType;\nuse Swoft\\Http\\Message\\Response;\nuse Swoft\\Http\\Server\\Exception\\Handler\\AbstractHttpErrorHandler;\nuse Swoft\\Log\\Helper\\CLog;\nuse Swoft\\Whoops\\WhoopsHandler;\nuse Throwable;\nuse function bean;\nuse function context;\nuse const APP_DEBUG;\n\n/**\n * Class HttpExceptionHandler\n *\n * @ExceptionHandler(\\Throwable::class)\n */\nclass HttpExceptionHandler extends AbstractHttpErrorHandler\n{\n    /**\n     * @param Throwable $e\n     * @param Response  $response\n     *\n     * @return Response\n     */\n    public function handle(Throwable $e, Response $response): Response\n    {\n        $request = context()-\u003egetRequest();\n        if ($request-\u003egetUriPath() === '/favicon.ico') {\n            return $response-\u003ewithStatus(404);\n        }\n\n        // Log\n        CLog::error($e-\u003egetMessage());\n\n        // Debug is false\n        if (!APP_DEBUG) {\n            return $response\n                -\u003ewithStatus(500)\n                -\u003ewithContent($e-\u003egetMessage());\n        }\n\n        // Debug is true\n        $whoops  = bean(WhoopsHandler::class);\n        $content = $whoops-\u003erun($e, $request);\n\n        return $response-\u003ewithContent($content)-\u003ewithContentType(ContentType::HTML);;\n    }\n}\n```\n\n## LICENSE\n\nThe Component is open-sourced software licensed under the [Apache license](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswoft-cloud%2Fswoft-whoops","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fswoft-cloud%2Fswoft-whoops","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswoft-cloud%2Fswoft-whoops/lists"}