From f80cdec1b9e4c0f8a77ff11d5b42723434be2219 Mon Sep 17 00:00:00 2001 From: Eduard Lupacescu Date: Fri, 12 Nov 2021 11:34:15 +0200 Subject: [PATCH] Without exception handler. --- docs-v2/content/en/api/exception-handler.md | 63 --------------------- docs-v2/content/en/index.md | 1 - docs-v2/content/en/quickstart.md | 7 +-- 3 files changed, 1 insertion(+), 70 deletions(-) delete mode 100644 docs-v2/content/en/api/exception-handler.md diff --git a/docs-v2/content/en/api/exception-handler.md b/docs-v2/content/en/api/exception-handler.md deleted file mode 100644 index 69d6ba9c..00000000 --- a/docs-v2/content/en/api/exception-handler.md +++ /dev/null @@ -1,63 +0,0 @@ ---- -title: Exception Handling -menuTitle: Exceptions -category: API -position: 5 ---- - -When creating an API the exceptions usually should be handled and resolved before sending to the client. -This is usually done in the Laravel ExceptionHandler which transform the exception in a RestResponse and debug it for you into: - -- line -- code -- file -- stack trace - - -## Disable Restify exception handler -However Restify gives you a handy exception handler which is configured in the -`restify.exception_handler` you may want to delegate the exception handling to your application ExceptionHandler for more control. - -You can do that changing config by nullifying it or replace with another handler class: - -```php -[ - // config/restify.php - ... - - 'exception_handler' => null -] -``` - -## Intercept exceptions - -Intercepting exceptions for a specific request is breeze to do with Restify. -Let's assume we have the store users controller action: - -```php -use App\User; -use Binaryk\LaravelRestify\Controllers\RestController; -use Binaryk\LaravelRestify\Restify;use Illuminate\Http\Request;use Illuminate\Http\Response;use Illuminate\Support\Facades\Log; - -class UserController extends RestController -{ - /** - * Store a newly created resource in storage. - * - * @param Request $request - * @return Response - */ - public function store(Request $request) - { - // Intercept the exception handler and log the exception message - Restify::exceptionHandler(function ($request, Exception $exception) { - Log::alert($exception->getMessage()); - return Response::make('Something went wrong', $exception->getCode()); - }); - - return $this->response(User::create($request->all())); - } -} -``` - -As we can see the `exceptionHandler` callback receive the `$request` and thrown `$exception`. diff --git a/docs-v2/content/en/index.md b/docs-v2/content/en/index.md index f382170a..4b93832f 100644 --- a/docs-v2/content/en/index.md +++ b/docs-v2/content/en/index.md @@ -15,7 +15,6 @@ Laravel Restify is MIT Licensed and can be freely by anyone. 'Authentication with Sanctum', 'Handy Response maker', 'Powerful Search', -'Integrated Exception handler', 'JSON:API consistency' ]"> diff --git a/docs-v2/content/en/quickstart.md b/docs-v2/content/en/quickstart.md index c0954f4e..73c3415c 100644 --- a/docs-v2/content/en/quickstart.md +++ b/docs-v2/content/en/quickstart.md @@ -7,7 +7,7 @@ category: Getting Started Laravel Restify has a few requirements you should be aware of before installing: - + ## Installing Laravel Restify @@ -86,11 +86,6 @@ You may notice that Restify also use the `EnsureJsonApiHeaderMiddleware` middlew the `application/vnd.api+json` Accept header for your API requests. So make sure, even when using Postman (or something else) for making requests, that this `Accept header` is applied. -### Exception Handling - -The `exception_handler` configuration allow you to use another default Exception Handler instead of the one Laravel -provides by default. If you want to keep the default one, just left this configuration as `null`. - ## Generate repository Creating a new repository can be done via restify command: