In the wiki you see the following to register exception responses, this seems to be specific for lumen. Where and how to I do this in a laravel 5.2 installation.
app('Dingo\Api\Exception\Handler')->register(function (Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException $exception) {
return Response::make(['error' => 'Hey, what do you think you are doing!?'], 401);
});
Hey, so here is how i did it :)
Ex of provider:
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Routing\Router;
/**
* Class ExceptionsServiceProvider - Hacky?!
* @package App\Providers
*/
class ExceptionsServiceProvider extends ServiceProvider
{
/**
* @return void
*/
public function boot(){}
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
app('Dingo\Api\Exception\Handler')->register(function (\Illuminate\Database\Eloquent\ModelNotFoundException $exception) {
throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
});
}
}
Razvan.
That worked, thank you :)
You should close this issue if it's resolved - Jason already has a enough to go through!
Hi @SteveAzz,
i did it the same but i have error:
Unresolvable dependency resolving [Parameter #1 [
Can you suggest solution?
@cona88 Can you please show your code
@SteveAzz
In my config/app.php
/*
* Application Service Providers...
*/
App\Providers\AppServiceProvider::class,
App\Providers\AuthServiceProvider::class,
App\Providers\EventServiceProvider::class,
App\Providers\RouteServiceProvider::class,
App\Providers\ExceptionsServiceProvider::class,
in Providers/ExceptionsServiceProvider.php
`
namespace AppProviders;
use IlluminateSupportServiceProvider;
class ExceptionsServiceProvider extends ServiceProvider
{
public function boot(){}
public function register()
{
app('Dingo\Api\Exception\Handler')->register(function (Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException $exception) {
return Response::make(['error' => 'Hey, what do you think you are doing!?'], 401);
});
}
}`
Please help!
Hello, I have the following in my register method
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
app('Dingo\Api\Exception\Handler')->register(function (\Illuminate\Database\Eloquent\ModelNotFoundException $exception) {
throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
});
}
Hope this helps, if you fix it tell me how you fixed it please
@SteveAzz
I fixed it,
In the app.php: i move App\Providers\ExceptionsServiceProvider::class, to the end of 'providers'
@SteveAzz you should put your code in 'boot()' method
Most helpful comment
@SteveAzz you should put your code in 'boot()' method