MarcinOrlowski / laravel-api-response-builder

Builds nice, normalized and easy to consume REST JSON responses for Laravel powered APIs.
MIT License
721 stars 79 forks source link

"Undefined array key" for ex handler config lacking i.e. api_code entry. #226

Open MarcinOrlowski opened 2 years ago

MarcinOrlowski commented 2 years ago

I have checked this

/** @var \Symfony\Component\HttpKernel\Exception\HttpException $ex */
$http_code = $ex->getStatusCode();

And $ex->getStatusCode() indeed returns 404, but at the same time, the final output has 500 status code. Here, I just opened a non-existent route: image

I tried to implement your solution:

  \Symfony\Component\HttpKernel\Exception\HttpException::class => [
      'handler' => \MarcinOrlowski\ResponseBuilder\ExceptionHandlers\HttpExceptionHandler::class,
      'pri' => -100,
      'config' => [
          Symfony\Component\HttpFoundation\Response::HTTP_NOT_FOUND => [
              'http_code' => Symfony\Component\HttpFoundation\Response::HTTP_NOT_FOUND,
          ],

And after that, I receive this error whenever I try to access a wrong route:

{"success":false,"code":113,"locale":"en","message":"Undefined array key \u0022api_code\u0022","data":null,"debug":{"trace":{"class":"ErrorException","file":"\/var\/www\/api\/vendor\/marcin-orlowski\/laravel-api-response-builder\/src\/ExceptionHandlerHelper.php","line":104}}}

Originally posted by @beeyev in https://github.com/MarcinOrlowski/laravel-api-response-builder/discussions/225#discussioncomment-2238369

beeyev commented 2 years ago

Well, it seems, that this problem is a bit bigger. If I try to access a post route as get, it should return 405 code, but instead, it returns 500

beeyev commented 2 years ago

Any news?

MarcinOrlowski commented 2 years ago

Unfortunately I haven't had time to take a look at this. Let me try over forthcoming weekend.