{"id":36981323,"url":"https://github.com/mlanin/laravel-api-exceptions","last_synced_at":"2026-01-13T22:51:09.672Z","repository":{"id":9492154,"uuid":"62298521","full_name":"mlanin/laravel-api-exceptions","owner":"mlanin","description":"All in one solution for exception for JSON REST APIs on Laravel and Lumen.","archived":false,"fork":false,"pushed_at":"2025-02-27T07:26:58.000Z","size":83,"stargazers_count":40,"open_issues_count":1,"forks_count":9,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-10-24T18:14:15.508Z","etag":null,"topics":["api","exceptions","laravel"],"latest_commit_sha":null,"homepage":"https://blog.lanin.me/api-exceptions-for-laravel/","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/mlanin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-06-30T09:33:28.000Z","updated_at":"2025-02-27T06:19:59.000Z","dependencies_parsed_at":"2022-08-07T05:01:04.980Z","dependency_job_id":null,"html_url":"https://github.com/mlanin/laravel-api-exceptions","commit_stats":null,"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"purl":"pkg:github/mlanin/laravel-api-exceptions","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlanin%2Flaravel-api-exceptions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlanin%2Flaravel-api-exceptions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlanin%2Flaravel-api-exceptions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlanin%2Flaravel-api-exceptions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mlanin","download_url":"https://codeload.github.com/mlanin/laravel-api-exceptions/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlanin%2Flaravel-api-exceptions/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28402160,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-13T14:36:09.778Z","status":"ssl_error","status_checked_at":"2026-01-13T14:35:19.697Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["api","exceptions","laravel"],"created_at":"2026-01-13T22:51:09.032Z","updated_at":"2026-01-13T22:51:09.667Z","avatar_url":"https://github.com/mlanin.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel-API-Exceptions\n[![Travis](https://img.shields.io/travis/rust-lang/rust.svg)](https://travis-ci.org/mlanin/laravel-api-exceptions)\n\n\u003e All in one solution for exception for JSON REST APIs on Laravel and Lumen.\n\n## About\n\nThe goal of this package is to provide you with a set of most common exceptions that may be needed while developing JSON REST API. It also:\n\n* Handles exceptions output.\n* Handles exceptions report to logs.\n* Overwrites default Validator to make validation errors more verbose.\n* Has a FormRequest that to handle validation errors and pass them to ApiExceptions layer.\n\n## Installation\n\n[PHP](https://php.net) 5.4+ or [HHVM](http://hhvm.com) 3.3+, [Composer](https://getcomposer.org) and [Laravel](http://laravel.com) 5.1+ are required.\n\nTo get the latest version of Laravel Laravel-API-Debugger, simply add the following line to the require block of your `composer.json` file.\n\nFor Laravel 5.1\n```\n\"lanin/laravel-api-exceptions\": \"^0.1.0\"\n```\n\nFor Laravel 5.3\n```\n\"lanin/laravel-api-exceptions\": \"^1.0.0\"\n```\n\nYou'll then need to run `composer install` or `composer update` to download it and have the autoloader updated.\n\nOnce Laravel-API-Exceptions is installed, if you're using Laravel 5.1, 5.2, 5.3, and 5.4, you need to register the service provider. Open up `config/app.php` and add the following to the providers key.\n\n```php\nLanin\\Laravel\\ApiExceptions\\ApiExceptionsServiceProvider::class,\n```\n\nIf you're using Laravel 5.5, you don't need to add anything in `config/app.php`. It will use package auto discovery feature in Laravel 5.5.\n\n### Exceptions\n\nEvery ApiException can be thrown as a normal exception and they will be automatically serialized to JSON with corresponding HTTP status, if user wants json:\n\n```json\n{\n    \"id\": \"not_found\",\n    \"message\": \"Requested object not found.\"\n}\n```\n\nThis object will be also populated with trace info, when `APP_DEBUG` is true.\n\nAlso it can have `meta` attribute when there is additional info. For example for validation errors:\n```json\n{\n\t\"id\": \"validation_failed\",\n\t\"message\": \"Validation failed.\",\n\t\"meta\": {\n\t\t\"errors\": {\n\t\t\t\"tags\": [{\n\t\t\t\t\"rule\": \"max.array\",\n\t\t\t\t\"message\": \"The tags may not have more than 10 items.\",\n\t\t\t\t\"parameters\": [\"10\"]\n\t\t\t}]\n\t\t}\n\t}\n}\n```\n\nFor `ValidationApiException`, meta attribute has `errors` object that contains validations errors.\nEvery attribute of this object is a name of a request parameter to validate to and value is an array of errors with description.\n\n#### Customization\n\nYou can customize errors APU response by overriding `formatApiResponse` method in your ExceptionsHandler.\n\nFor example if you want to put everything under `error` attribute, you can do it like this:\n\n```php\n/**\n * Format error message for API response.\n *\n * @param  ApiException  $exception\n * @return mixed\n */\nprotected function formatApiResponse(ApiException $exception)\n{\n    return [\n        'error' =\u003e $exception-\u003etoArray(),\n    ];\n}\n```\n\n### Handler\n\nExtend your default exceptions handler with:\n\n* `\\Lanin\\Laravel\\ApiExceptions\\LaravelExceptionHandler` for Laravel\n* `\\Lanin\\Laravel\\ApiExceptions\\LumenExceptionHandler` for Lumen\n\nAnd remove everything else. Example:\n\n```php\n\u003c?php\n\nnamespace App\\Exceptions;\n\nuse Lanin\\Laravel\\ApiExceptions\\LaravelExceptionHandler;\n\nclass Handler extends LaravelExceptionHandler\n{\n\n}\n```\n\n### FormRequest\n\nTo use FormRequest extend all your Request classes with `\\Lanin\\Laravel\\ApiExceptions\\Support\\Request`.\nIt will automatically support validation errors and pass them to the output.\n\nIt also has a very handy helper method `validatedOnly()` that returns from request only those items that are registered in rules method.\n\n## Contributing\n\nPlease feel free to fork this package and contribute by submitting a pull request to enhance the functionalities.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmlanin%2Flaravel-api-exceptions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmlanin%2Flaravel-api-exceptions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmlanin%2Flaravel-api-exceptions/lists"}