{"id":27555240,"url":"https://github.com/attributes-php/wp-exceptions","last_synced_at":"2026-01-22T13:47:55.315Z","repository":{"id":143295438,"uuid":"615337535","full_name":"Attributes-PHP/wp-exceptions","owner":"Attributes-PHP","description":"Don't feel sorry to interrupt. WordPress exceptions made simple.","archived":false,"fork":false,"pushed_at":"2024-05-16T10:59:36.000Z","size":38,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-19T00:08:15.643Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Attributes-PHP.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,"governance":null}},"created_at":"2023-03-17T13:21:24.000Z","updated_at":"2025-04-18T18:50:47.000Z","dependencies_parsed_at":"2023-11-19T10:21:05.332Z","dependency_job_id":"66c82bbc-f74f-4e4f-ac0b-a5858ec4f1b8","html_url":"https://github.com/Attributes-PHP/wp-exceptions","commit_stats":null,"previous_names":["myspanishnow/wp-exceptions-original","matapatos/wp-exceptions"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Attributes-PHP%2Fwp-exceptions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Attributes-PHP%2Fwp-exceptions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Attributes-PHP%2Fwp-exceptions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Attributes-PHP%2Fwp-exceptions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Attributes-PHP","download_url":"https://codeload.github.com/Attributes-PHP/wp-exceptions/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249740883,"owners_count":21318712,"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":[],"created_at":"2025-04-19T16:44:18.777Z","updated_at":"2026-01-22T13:47:55.311Z","avatar_url":"https://github.com/Attributes-PHP.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# WP Exceptions\n\n\u003cimg src=\"https://raw.githubusercontent.com/Attributes-PHP/wp-exceptions/main/images/wp-exceptions-wallpaper.png\" alt=\"Throw exceptions instead of returning WP_Error\"\u003e\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/Attributes-PHP/wp-exceptions/actions\"\u003e\u003cimg alt=\"GitHub Actions Workflow Status (main)\" src=\"https://img.shields.io/github/actions/workflow/status/Attributes-PHP/wp-exceptions/tests.yml\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://codecov.io/gh/Attributes-PHP/wp-exceptions\" \u003e\u003cimg alt=\"Code Coverage\" src=\"https://codecov.io/gh/Attributes-PHP/wp-exceptions/graph/badge.svg?token=8N7N9NMGLG\"/\u003e\u003c/a\u003e\n    \u003ca href=\"https://packagist.org/packages/Attributes-PHP/wp-exceptions\"\u003e\u003cimg alt=\"Latest Version\" src=\"https://img.shields.io/packagist/v/Attributes-PHP/wp-exceptions\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://packagist.org/packages/Attributes-PHP/wp-exceptions\"\u003e\u003cimg alt=\"Supported WordPress Versions\" src=\"https://img.shields.io/badge/6.x-versions?logo=wordpress\u0026label=versions\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://opensource.org/licenses/MIT\"\u003e\u003cimg alt=\"Software License\" src=\"https://img.shields.io/badge/Licence-MIT-brightgreen\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n------\n*WP_Error* was a cool feature in 2007 but today we should throw exceptions.\n\n## Features\n\n- Handles *HttpExceptions* like WP_Error's\n- Supports custom handlers for custom exceptions\n- Compatible with other exception handlers (e.g. [Whoops](https://github.com/filp/whoops))\n\n## Requirements\n\n- PHP 8.1+\n- WordPress 6.x\n\nWe aim to support versions that haven't reached their end-of-life.\n\n## Installation\n\n```bash\ncomposer require attributes-php/wp-exceptions\n```\n\n## How it works?\n\nOnce the ExceptionHandler is registered, you can start throwing exceptions\n\n```php\nuse Attributes\\Wp\\Exceptions\\ExceptionHandler;\n\nExceptionHandler::register();\n```\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003ch4\u003eHow \u003cb\u003eHttpExceptions\u003c/b\u003e are displayed?\u003c/h4\u003e\u003c/summary\u003e\n\nWordPress itself handles how an \u003ca href=\"https://github.com/Attributes-PHP/wp-exceptions/blob/main/src/HttpException.php\" target=\"_blank\"\u003e\u003cb\u003eHttpException\u003c/b\u003e\u003c/a\u003e\nis displayed to the user. In a nutshell, those exceptions are converted into a \u003ca href=\"https://developer.wordpress.org/reference/classes/wp_error/\" target=\"_blank\"\u003e\u003cb\u003eWP_Error\u003c/b\u003e\u003c/a\u003e\nwhich is then handled by WordPress via \u003ca href=\"https://developer.wordpress.org/reference/functions/wp_die/\" target=\"_blank\"\u003e\u003ci\u003ewp_die\u003c/i\u003e\u003c/a\u003e function.\n\nThis means, that the following types of requests are supported:\n\n- ✅ Ajax\n- ✅ JSON\n- ✅ JSONP\n- ✅ XMLRPC\n- ✅ XML\n- ✅ All other types e.g. HTML\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003ch4\u003eHow to send custom HTTP headers?\u003c/h4\u003e\u003c/summary\u003e\n\n```php\nthrow new HttpException(headers: ['My-Header' =\u003e 'Value 123']);\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003ch4\u003eHow to add custom handlers?\u003c/h4\u003e\u003c/summary\u003e\n\n```php\n$exceptionHandler = ExceptionHandler::getOrCreate();\n$exceptionHandler-\u003eonException(CustomException::class, fn($ex) =\u003e echo \"A custom exception has been raised\");\n```\n\nEnsure to add handlers which supports all types of possible requests e.g. JSON, XML, etc\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003ch4\u003eSage theme support\u003c/h4\u003e\u003c/summary\u003e\n\nIf you are using \u003ca href=\"https://github.com/roots/sage\" target=\"_blank\"\u003e\u003ci\u003eSage\u003c/i\u003e\u003c/a\u003e theme, you would need to register or re-register\nthis exception handler after the application is configured. Otherwise, this exception handler might be overrided.\n\n```php\n// themes/sage/functions.php\n\nApplication::configure()\n    -\u003ewithProviders([\n        App\\Providers\\ThemeServiceProvider::class,\n    ])\n    -\u003eboot();\n\nExceptionHandler::register(force: true); // We are using force true in case the ExceptionHandler has been registered before e.g. in a plugin\n```\n\u003c/details\u003e\n\nWP Exceptions was created by **[André Gil](https://www.linkedin.com/in/andre-gil/)** and is open-sourced software licensed under the **[MIT license](https://opensource.org/licenses/MIT)**.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fattributes-php%2Fwp-exceptions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fattributes-php%2Fwp-exceptions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fattributes-php%2Fwp-exceptions/lists"}