Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom error handler problems #1309

Closed
fico7489 opened this issue Jan 19, 2017 · 1 comment
Closed

Custom error handler problems #1309

fico7489 opened this issue Jan 19, 2017 · 1 comment

Comments

@fico7489
Copy link

fico7489 commented Jan 19, 2017

I have this code in AppServiceProvider:

   $exception->register(function(ModelNotFoundException $e) {
        return \Response::make([]);
    });

And I am getting error :

{
  "message": "Call to a member function requestIsConditional() on null",
  "status_code": 500,
  "debug": {
    "line": 653,
    "file": "/home/vagrant/green-rush/vendor/dingo/api/src/Routing/Router.php",
    "class": "Symfony\\Component\\Debug\\Exception\\FatalThrowableError",
    "trace": [
      "#0 /home/vagrant/green-rush/vendor/dingo/api/src/Routing/Router.php(623): Dingo\\Api\\Routing\\Router->requestIsConditional()",
      "#1 /home/vagrant/green-rush/vendor/dingo/api/src/Routing/Router.php(589): Dingo\\Api\\Routing\\Router->prepareResponse(Object(Dingo\\Api\\Http\\Response), Object(Dingo\\Api\\Http\\Request), 'json')",
      "#2 /home/vagrant/green-rush/vendor/dingo/api/src/Http/Middleware/Request.php(123): Dingo\\Api\\Routing\\Router->dispatch(Object(Dingo\\Api\\Http\\Request))",
      "#3 [internal function]: Dingo\\Api\\Http\\Middleware\\Request->Dingo\\Api\\Http\\Middleware\\{closure}(Object(Dingo\\Api\\Http\\Request))",
      "#4 /home/vagrant/green-rush/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(150): call_user_func(Object(Closure), Object(Dingo\\Api\\Http\\Request))",
      "#5 /home/vagrant/green-rush/vendor/barryvdh/laravel-debugbar/src/Middleware/Debugbar.php(51): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Dingo\\Api\\Http\\Request))",
      "#6 [internal function]: Barryvdh\\Debugbar\\Middleware\\Debugbar->handle(Object(Dingo\\Api\\Http\\Request), Object(Closure))",
      "#7 /home/vagrant/green-rush/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(136): call_user_func_array(Array, Array)",
      "#8 /home/vagrant/green-rush/vendor/fideloper/proxy/src/TrustProxies.php(41): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Dingo\\Api\\Http\\Request))",
      "#9 [internal function]: Fideloper\\Proxy\\TrustProxies->handle(Object(Dingo\\Api\\Http\\Request), Object(Closure))",
      "#10 /home/vagrant/green-rush/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(136): call_user_func_array(Array, Array)",
      "#11 /home/vagrant/green-rush/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php(44): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Dingo\\Api\\Http\\Request))",
      "#12 [internal function]: Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode->handle(Object(Dingo\\Api\\Http\\Request), Object(Closure))",
      "#13 /home/vagrant/green-rush/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(136): call_user_func_array(Array, Array)",
      "#14 [internal function]: Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Dingo\\Api\\Http\\Request))",
      "#15 /home/vagrant/green-rush/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(102): call_user_func(Object(Closure), Object(Dingo\\Api\\Http\\Request))",
      "#16 /home/vagrant/green-rush/vendor/dingo/api/src/Http/Middleware/Request.php(124): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))",
      "#17 /home/vagrant/green-rush/vendor/dingo/api/src/Http/Middleware/Request.php(100): Dingo\\Api\\Http\\Middleware\\Request->sendRequestThroughRouter(Object(Dingo\\Api\\Http\\Request))",
      "#18 [internal function]: Dingo\\Api\\Http\\Middleware\\Request->handle(Object(Dingo\\Api\\Http\\Request), Object(Closure))",
      "#19 /home/vagrant/green-rush/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(136): call_user_func_array(Array, Array)",
      "#20 [internal function]: Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))",
      "#21 /home/vagrant/green-rush/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\\Http\\Request))",
      "#22 [internal function]: Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))",
      "#23 /home/vagrant/green-rush/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(102): call_user_func(Object(Closure), Object(Illuminate\\Http\\Request))",
      "#24 /home/vagrant/green-rush/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(132): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))",
      "#25 /home/vagrant/green-rush/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(99): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter(Object(Illuminate\\Http\\Request))",
      "#26 /home/vagrant/green-rush/public/index.php(53): Illuminate\\Foundation\\Http\\Kernel->handle(Object(Illuminate\\Http\\Request))",
      "#27 {main}"
    ]
  }
}

But this works fine:

 $exception->register(function(ModelNotFoundException $e) {
        return 'error';
    });

In your documentation you are returning like:

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);
});
@shibby
Copy link

shibby commented Apr 27, 2017

getting same issue.
i've handled HttpException.
app(Handler::class)->register(function (HttpException $exception) { .....

if endpoint is not exists, getting exact same error.

@fico7489 fico7489 closed this as completed Nov 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants