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

Exception Handler always returns blank 500 internal server error #555

Closed
stefanwub opened this issue Sep 22, 2020 · 8 comments
Closed

Exception Handler always returns blank 500 internal server error #555

stefanwub opened this issue Sep 22, 2020 · 8 comments

Comments

@stefanwub
Copy link

I'm using Laravel 8 with version 3.0. When I change the exception handler exactly as described in the docs (https://laravel-json-api.readthedocs.io/en/latest/installation/) all the errors in the application give a blank page with 500 internal server error.

I've done some digging and the functions isJsonApi() and renderJsonApi() from the HandlesErrors trait seems to be the problem. Looks like a bug? Or am I missing something here?

@stefanwub
Copy link
Author

The issue seems to be resolved when I create a json-api-default.php config file. Is that right? I do have a custom default name added to the boot method of a service provider. As described here: https://laravel-json-api.readthedocs.io/en/latest/basics/api/

@lindyhopchris
Copy link
Member

When you get the 500 internal server error, what's the exception that's being reported to your log file?

@lindyhopchris
Copy link
Member

The issue seems to be resolved when I create a json-api-default.php config file. Is that right? I do have a custom default name added to the boot method of a service provider. As described here: https://laravel-json-api.readthedocs.io/en/latest/basics/api/

You shouldn't have to create the default config if you're changing the name of the default API, so something is definitely not right if that's the case. It'd help if you could let me know the exception in the log file.

@stefanwub
Copy link
Author

My mistake, it looks like the default api name was not added to the right place.

Thanks!

@brewers-dev-phil
Copy link

I am having a similar issue but I am using the default api name. Whenever a validation rule that I have added fails it falls over with a 500 error. This is Laravel 8 and version 3.

This is the error stack:
CloudCreativity\LaravelJsonApi\Exceptions\ValidationException: JSON API error in file /var/www/html/webservices.brewers.co.uk/vendor/cloudcreativity/laravel-json-api/src/Exceptions/ValidationException.php on line 49

#0 /var/www/html/webservices.brewers.co.uk/vendor/cloudcreativity/laravel-json-api/src/Http/Requests/ValidatedRequest.php(273): CloudCreativity\LaravelJsonApi\Exceptions\ValidationException::create(Object(CloudCreativity\LaravelJsonApi\Validation\Validator))
#1 /var/www/html/webservices.brewers.co.uk/vendor/cloudcreativity/laravel-json-api/src/Http/Requests/ValidatedRequest.php(262): CloudCreativity\LaravelJsonApi\Http\Requests\ValidatedRequest->failedValidation(Object(CloudCreativity\LaravelJsonApi\Validation\Validator))
#2 /var/www/html/webservices.brewers.co.uk/vendor/cloudcreativity/laravel-json-api/src/Http/Requests/CreateResource.php(69): CloudCreativity\LaravelJsonApi\Http\Requests\ValidatedRequest->passes(Object(CloudCreativity\LaravelJsonApi\Validation\Validator))
#3 /var/www/html/webservices.brewers.co.uk/vendor/cloudcreativity/laravel-json-api/src/Http/Requests/ValidatedRequest.php(231): CloudCreativity\LaravelJsonApi\Http\Requests\CreateResource->validateDocument()
#4 /var/www/html/webservices.brewers.co.uk/vendor/laravel/framework/src/Illuminate/Foundation/Providers/FormRequestServiceProvider.php(30): CloudCreativity\LaravelJsonApi\Http\Requests\ValidatedRequest->validateResolved()
#5 /var/www/html/webservices.brewers.co.uk/vendor/laravel/framework/src/Illuminate/Container/Container.php(1141): Illuminate\Foundation\Providers\FormRequestServiceProvider->Illuminate\Foundation\Providers{closure}(Object(CloudCreativity\LaravelJsonApi\Http\Requests\CreateResource), Object(Illuminate\Foundation\Application))
#6 /var/www/html/webservices.brewers.co.uk/vendor/laravel/framework/src/Illuminate/Container/Container.php(1105): Illuminate\Container\Container->fireCallbackArray(Object(CloudCreativity\LaravelJsonApi\Http\Requests\CreateResource), Array)
#7 /var/www/html/webservices.brewers.co.uk/vendor/laravel/framework/src/Illuminate/Container/Container.php(1090): Illuminate\Container\Container->fireAfterResolvingCallbacks('CloudCreativity...', Object(CloudCreativity\LaravelJsonApi\Http\Requests\CreateResource))
#8 /var/www/html/webservices.brewers.co.uk/vendor/laravel/framework/src/Illuminate/Container/Container.php(711): Illuminate\Container\Container->fireResolvingCallbacks('CloudCreativity...', Object(CloudCreativity\LaravelJsonApi\Http\Requests\CreateResource))
#9 /var/www/html/webservices.brewers.co.uk/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(796): Illuminate\Container\Container->resolve('CloudCreativity...', Array, true)
#10 /var/www/html/webservices.brewers.co.uk/vendor/laravel/framework/src/Illuminate/Container/Container.php(637): Illuminate\Foundation\Application->resolve('CloudCreativity...', Array)
#11 /var/www/html/webservices.brewers.co.uk/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(781): Illuminate\Container\Container->make('CloudCreativity...', Array)
#12 /var/www/html/webservices.brewers.co.uk/vendor/laravel/framework/src/Illuminate/Routing/RouteDependencyResolverTrait.php(79): Illuminate\Foundation\Application->make('CloudCreativity...')
#13 /var/www/html/webservices.brewers.co.uk/vendor/laravel/framework/src/Illuminate/Routing/RouteDependencyResolverTrait.php(48): Illuminate\Routing\ControllerDispatcher->transformDependency(Object(ReflectionParameter), Array, Object(stdClass))
#14 /var/www/html/webservices.brewers.co.uk/vendor/laravel/framework/src/Illuminate/Routing/RouteDependencyResolverTrait.php(28): Illuminate\Routing\ControllerDispatcher->resolveMethodDependencies(Array, Object(ReflectionMethod))
#15 /var/www/html/webservices.brewers.co.uk/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(41): Illuminate\Routing\ControllerDispatcher->resolveClassMethodDependencies(Array, Object(App\Http\Controllers\Api\OrdersController), 'create')
#16 /var/www/html/webservices.brewers.co.uk/vendor/laravel/framework/src/Illuminate/Routing/Route.php(255): Illuminate\Routing\ControllerDispatcher->dispatch(Object(Illuminate\Routing\Route), Object(App\Http\Controllers\Api\OrdersController), 'create')
#17 /var/www/html/webservices.brewers.co.uk/vendor/laravel/framework/src/Illuminate/Routing/Route.php(197): Illuminate\Routing\Route->runController()
#18 /var/www/html/webservices.brewers.co.uk/vendor/laravel/framework/src/Illuminate/Routing/Router.php(691): Illuminate\Routing\Route->run()
#19 /var/www/html/webservices.brewers.co.uk/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\Routing\Router->Illuminate\Routing{closure}(Object(Illuminate\Http\Request))
#20 /var/www/html/webservices.brewers.co.uk/vendor/cloudcreativity/laravel-json-api/src/Http/Middleware/NegotiateContent.php(102): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Illuminate\Http\Request))
#21 /var/www/html/webservices.brewers.co.uk/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): CloudCreativity\LaravelJsonApi\Http\Middleware\NegotiateContent->handle(Object(Illuminate\Http\Request), Object(Closure))
#22 /var/www/html/webservices.brewers.co.uk/vendor/cloudcreativity/laravel-json-api/src/Http/Middleware/BootJsonApi.php(82): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Illuminate\Http\Request))
#23 /var/www/html/webservices.brewers.co.uk/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): CloudCreativity\LaravelJsonApi\Http\Middleware\BootJsonApi->handle(Object(Illuminate\Http\Request), Object(Closure), 'default')
#24 /var/www/html/webservices.brewers.co.uk/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php(41): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Illuminate\Http\Request))
#25 /var/www/html/webservices.brewers.co.uk/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Routing\Middleware\SubstituteBindings->handle(Object(Illuminate\Http\Request), Object(Closure))
#26 /var/www/html/webservices.brewers.co.uk/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php(127): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Illuminate\Http\Request))
#27 /var/www/html/webservices.brewers.co.uk/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php(103): Illuminate\Routing\Middleware\ThrottleRequests->handleRequest(Object(Illuminate\Http\Request), Object(Closure), Array)
#28 /var/www/html/webservices.brewers.co.uk/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php(55): Illuminate\Routing\Middleware\ThrottleRequests->handleRequestUsingNamedLimiter(Object(Illuminate\Http\Request), Object(Closure), 'api', Object(Closure))
#29 /var/www/html/webservices.brewers.co.uk/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Routing\Middleware\ThrottleRequests->handle(Object(Illuminate\Http\Request), Object(Closure), 'api')
#30 /var/www/html/webservices.brewers.co.uk/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Illuminate\Http\Request))
#31 /var/www/html/webservices.brewers.co.uk/vendor/laravel/framework/src/Illuminate/Routing/Router.php(693): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#32 /var/www/html/webservices.brewers.co.uk/vendor/laravel/framework/src/Illuminate/Routing/Router.php(668): Illuminate\Routing\Router->runRouteWithinStack(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request))
#33 /var/www/html/webservices.brewers.co.uk/vendor/laravel/framework/src/Illuminate/Routing/Router.php(634): Illuminate\Routing\Router->runRoute(Object(Illuminate\Http\Request), Object(Illuminate\Routing\Route))
#34 /var/www/html/webservices.brewers.co.uk/vendor/laravel/framework/src/Illuminate/Routing/Router.php(623): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))
#35 /var/www/html/webservices.brewers.co.uk/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(166): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))
#36 /var/www/html/webservices.brewers.co.uk/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http{closure}(Object(Illuminate\Http\Request))
#37 /var/www/html/webservices.brewers.co.uk/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Illuminate\Http\Request))
#38 /var/www/html/webservices.brewers.co.uk/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle(Object(Illuminate\Http\Request), Object(Closure))
#39 /var/www/html/webservices.brewers.co.uk/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Illuminate\Http\Request))
#40 /var/www/html/webservices.brewers.co.uk/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle(Object(Illuminate\Http\Request), Object(Closure))
#41 /var/www/html/webservices.brewers.co.uk/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php(27): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Illuminate\Http\Request))
#42 /var/www/html/webservices.brewers.co.uk/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Foundation\Http\Middleware\ValidatePostSize->handle(Object(Illuminate\Http\Request), Object(Closure))
#43 /var/www/html/webservices.brewers.co.uk/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php(87): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Illuminate\Http\Request))
#44 /var/www/html/webservices.brewers.co.uk/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance->handle(Object(Illuminate\Http\Request), Object(Closure))
#45 /var/www/html/webservices.brewers.co.uk/vendor/fruitcake/laravel-cors/src/HandleCors.php(57): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Illuminate\Http\Request))
#46 /var/www/html/webservices.brewers.co.uk/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Fruitcake\Cors\HandleCors->handle(Object(Illuminate\Http\Request), Object(Closure))
#47 /var/www/html/webservices.brewers.co.uk/vendor/fideloper/proxy/src/TrustProxies.php(57): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Illuminate\Http\Request))
#48 /var/www/html/webservices.brewers.co.uk/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Fideloper\Proxy\TrustProxies->handle(Object(Illuminate\Http\Request), Object(Closure))
#49 /var/www/html/webservices.brewers.co.uk/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Illuminate\Http\Request))
#50 /var/www/html/webservices.brewers.co.uk/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(141): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#51 /var/www/html/webservices.brewers.co.uk/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(110): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request))
#52 /var/www/html/webservices.brewers.co.uk/public/index.php(52): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))
#53 {main}

@lindyhopchris
Copy link
Member

@brewers-dev-phil can you share your Exception handler and confirm you've followed the installation instructions for what needs adding to the exception handler?
https://laravel-json-api.readthedocs.io/en/latest/installation/#exception-handling

All the tests for validation exceptions are passing in Laravel 8, so I suspect it's something to do with your set up.

@brewers-dev-phil
Copy link

@brewers-dev-phil can you share your Exception handler and confirm you've followed the installation instructions for what needs adding to the exception handler?
https://laravel-json-api.readthedocs.io/en/latest/installation/#exception-handling

All the tests for validation exceptions are passing in Laravel 8, so I suspect it's something to do with your set up.

Hello Chris,

Had missed that - all sorted now. Apologies and thanks for pointing me in the right direction.

@lindyhopchris
Copy link
Member

No problem - glad you got it sorted!

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

3 participants