-
-
Notifications
You must be signed in to change notification settings - Fork 374
Custom Exception Handling
As of v13.0.0, the "login" page was removed and all internal exceptions were modified to be agnostic.
There are currently a few exceptions:
-
ApiException
happens for API errors -
MissingShopDomainException
happens for bad sessions or direct access to app outside of Shopify -
ChargeNotRecurringException
happens when trying to apply usage charges to a one-time charge -
ChargeNotRecurringOrOneTimeException
happens when trying to modify a usage charge by mistake -
SignatureVerificationException
happens when the HMAC signature, proxy signature, or webhook signature does not validate
Without modification, in development, you will see the full exception stack from Laravel. On production, you will see Laravel's production handler for errors.
If you would like to handle these exceptions on your own, you can open app/Exceptions/Handler.php
in your app and modify the render
method:
public function render($request, Throwable $exception)
{
if ($exception instanceof \Osiset\ShopifyApp\Exceptions\MissingShopDomainException) {
return response()->view('errors.custom', [], 500);
}
// If you would like to capture ALL errors from this page
//
// if ($exception instanceof \Osiset\ShopifyApp\Exceptions\BaseException) {
// return response()->view('errors.custom', [], 500);
// }
return parent::render($request, $exception);
}
Now you are able to handle each exception, or all of them, in any manner you require.
If you are using larave 8 and want to handle the exception "MissingShopDomainException" then you can handle this exception using handler.php in laravel. Go to app->Exceptions->Handler and write below code:
Include this on top
use Osiset\ShopifyApp\Exceptions\MissingShopDomainException; use Illuminate\Support\Facades\Redirect;
And inside function register write:
public function register(){ $this->renderable(function(MissingShopDomainException $e){ return Redirect::to('https://www.shopify.com/in/login'); }); }
This will redirect to the shopify login page when anyone will try to hit the base url without login.
road map
Welcome to the wiki!
Please see the homepage for a list of relevant pages.