{"id":20548306,"url":"https://github.com/robrogers3/laravel-jsonaware-exception-handler","last_synced_at":"2025-06-23T00:36:30.608Z","repository":{"id":62536624,"uuid":"98529103","full_name":"robrogers3/laravel-jsonaware-exception-handler","owner":"robrogers3","description":"Provide Meaningful Ajax error messages for your Laravel Project.","archived":false,"fork":false,"pushed_at":"2018-06-02T20:52:38.000Z","size":45,"stargazers_count":6,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-14T10:55:28.825Z","etag":null,"topics":["ajax","custom","error-handling","exception-handler","javascript","json","laravel","laravel-exception-handler","service-provider"],"latest_commit_sha":null,"homepage":"","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/robrogers3.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":"2017-07-27T11:41:51.000Z","updated_at":"2025-03-02T14:07:55.000Z","dependencies_parsed_at":"2022-11-02T16:01:00.159Z","dependency_job_id":null,"html_url":"https://github.com/robrogers3/laravel-jsonaware-exception-handler","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/robrogers3/laravel-jsonaware-exception-handler","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robrogers3%2Flaravel-jsonaware-exception-handler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robrogers3%2Flaravel-jsonaware-exception-handler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robrogers3%2Flaravel-jsonaware-exception-handler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robrogers3%2Flaravel-jsonaware-exception-handler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/robrogers3","download_url":"https://codeload.github.com/robrogers3/laravel-jsonaware-exception-handler/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robrogers3%2Flaravel-jsonaware-exception-handler/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261391038,"owners_count":23151660,"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":["ajax","custom","error-handling","exception-handler","javascript","json","laravel","laravel-exception-handler","service-provider"],"created_at":"2024-11-16T02:13:00.825Z","updated_at":"2025-06-23T00:36:25.579Z","avatar_url":"https://github.com/robrogers3.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Latest Version on Packagist][ico-version]][link-packagist]\n[![Software License][ico-license]](LICENSE.md)\n[![Total Downloads][ico-downloads]][link-downloads]\n[![Build Status][ico-travis]][link-travis]\n\n# Laravel Json Aware Exception Handler\n\nEvery one likes cool error message pages. Github has an awesome 404.\n\nAnd it's very easy to create your own custom error pages for html responses.\n\nBut doing this for Ajax and Json responses meant either doing something generic or figuring out your own solution.\nOften something like returning an error message like  'Sorry we cant handle your request'. Nothing informative.\n\nThis package solves this problem.\n\nOnce it's installed. Tune your error messages for over a dozen possible error codes.\nYou can even add more. Just create a ZizzZazzException assign a status code to it, and a custom message. Done!\n\n## Installation\n\nInstall Laravel Json Aware Exception Handler with Composer.\n\n```bash\n$ composer require robrogers3/laravel-json-aware-exception-handler\n```\n\n## Configuration \n\n```php\nRobRogers3\\LaravelExceptionHandler\\ServiceProvider::class,\n```\n\n### Using it:\n\nOption 1: Update your .env file by adding this line:\n\nUSE_JSON_EXCEPTION_HANDLER=true\n\nThis will use the JsonHandler for json requests and the Laravel Exception Handler for regular requests.\n\nNote: it will completely ignore your app's Exception Handler. This means you can't override anything in this class.\n\nOption 2: Update your App Handler class to extend the JsonAwareExceptionHandler\n\nYou do not have to update your .env file.\n\nThe benefit of this is you can overide how the JsonAwareExceptionHandler\n\nTo do this you  need to change your `App\\Exceptions\\Handler` class to extend `RobRogers3\\LaravelExceptionHandler\\JsonAwareExceptionHandler` rather than extending `Illuminate\\Foundation\\Exceptions\\Handler`. Like so:\n\n\n```php\n\u003c?php\n\nuse RobRogers3\\LaravelExceptionHandler\\JsonAwareExceptionHandler;\n\nclass Handler extends JsonAwareExceptionHandler\n{\n    \n}\n```\n\n## Last Step\n\nYou need to run this artisan command:\n\n```bash\n$ artisan vendor:publish\n```\n\nThis will copy the exception messages to your local lang directory.\n\n\n## Optional Setup.\n\nOpen the exceptionmessages.php and change the messages you want to show for different http status codes.\n\nYou may want to change 401 to something more clever or more corporate. It's up to you.\n\n\n## Usage\n\n### Server Side Usage\n\nThere really is only one thing to use: Taking advantage of the MessagingException::class\n\nThrowing this with a custom message allows you to display something detailed or specific to the situtation.\n\n### Client Side Usage with Ajax\n\nHere's where you want to take advantage of this. \n\nTake a look at this handling of an ajax response error.\n\n\n```javascript\n\thandle (error) {\n\t       \n\t    if (error.response.data) {\n\t    //the error message returned by the json response corresponds to the error.response.data property\n\n\t    //Usually it's a string\n\t\t if (typeof error.response.data == 'string') {\n\t\t \n\t\t     return alert(error.response.data);\n\t\t }\n\n\t\t //validation errors are an array\n\t\t if (error.response.status == 422 \u0026\u0026 error.response.data.length) {\n\t\t     let errors = [];\n\n\t\t\t error.response.data.forEach(datum =\u003e {\n\t\t\t     errors.push(datum);\n\t\t\t });\n\t\t     \n\t\t     return alert(errors.join(\"\\n\"));\n\t\t }\n\n\t\t //used to handle a teapot message 418\n\t\t //can be a random exception you throw as say MessagingException\n\t\t \n\t\t //you can tweek your teapot messages to have an extra 'message' property. Up to you.\n\t\t //by default it doesn't \n\t\t if (error.response.status == 418 \u0026\u0026 error.response.data.message) {\n\t\t     return alert(error.response.data);\n\t\t }\n\t\t \n\t     }\n\t     return alert('We could not handle your request');\n\t}\n    }\n```\n\n\n[ico-version]: https://img.shields.io/packagist/v/robrogers3/laravel-jsonaware-exception-handler.svg?style=flat-square\n[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square\n[ico-travis]: https://img.shields.io/travis/robrogers3/laravel-jsonaware-exception-handler/master.svg?style=flat-square\n[ico-scrutinizer]: https://img.shields.io/scrutinizer/coverage/g/robrogers3/laraldap-auth.svg?style=flat-square\n[ico-code-quality]: https://img.shields.io/scrutinizer/g/robrogers3/laraldap-auth.svg?style=flat-square\n[ico-downloads]: https://img.shields.io/packagist/dt/robrogers3/laravel-jsonaware-exception-handler.svg?style=flat-square\n\n[link-packagist]: https://packagist.org/packages/robrogers3/laravel-jsonaware-exception-handler\n[link-travis]: https://travis-ci.org/robrogers3/laravel-jsonaware-exception-handler\n[link-scrutinizer]: https://scrutinizer-ci.com/g/robrogers3/laradauth/code-structure\n[link-code-quality]: https://scrutinizer-ci.com/g/robrogers3/laraldap-auth\n[link-downloads]: https://packagist.org/packages/robrogers3/laravel-jsonaware-exception-handler\n[link-author]: https://github.com/robrogers3\n[link-contributors]: ../../contributors\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobrogers3%2Flaravel-jsonaware-exception-handler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobrogers3%2Flaravel-jsonaware-exception-handler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobrogers3%2Flaravel-jsonaware-exception-handler/lists"}