-
Notifications
You must be signed in to change notification settings - Fork 107
Description
Hello. I'm on the task of developing an API and decided to implement this package. I'm getting an error that I wasn't able to figure out.
Problem description
Problem at parsing Laravel Exception. App container throws BindingResolutionException when instantiating LaravelJsonApi\Exceptions\ExceptionParser.
Further explanation and examples
I have created several resources and I'm getting 500 error coded responses when the Exception being thrown belongs to Laravel instead of LaravelJsonApi.
For instance, querying http://localhost:8000/api/v1/clients/2000 returns a response like the following, as expected because a client with such id doesn't exist in the database.
GET /api/v1/clients/2000? HTTP/1.1
{
"errors": [
{
"status": "404",
"title": "Not Found",
"detail": "Resource clients with id 2000 does not exist."
}
]
}
So, the exception handler that comes with this package seems to be working fine when dealing with LaravelJsonApi exceptions. The problem I'm encountering is when handling Laravel Exceptions. For example, the POST request below do create a new client when the company referenced exists. If the company id submitted is invalid, a PDOException (Integrity constraint violation) is thrown.
POST /api/v1/clients/ HTTP/1.1
Host: localhost:8000
Accept: application/vnd.api+json
Content-Type: application/vnd.api+json
{
"data": {
"type": "clients",
"attributes": {
"name": "Nacho",
"company_id": 8,
}
}
}
I'm expecting the Exception to be parsed, but the Container fails trying to instantiate the ExceptionParser, throwing the following exception in Container at method notInstantiable():
Illuminate\Contracts\Container\BindingResolutionException: Target [CloudCreativity\LaravelJsonApi\Contracts\Exceptions\ErrorIdAllocatorInterface] is not instantiable while building [CloudCreativity\LaravelJsonApi\Exceptions\ExceptionParser]. And therefore returning a 500 status code.
Notes
- Although this is my first time implementing this package, the setup was done according to the docs. All my resources routes have the following middlewares (from php artisan route:list): api, auth:api, json-api:default, json-api.content.
- Authentication is being handled by Laravel Passport OAuth 2.0.
- Maybe related to Auth middleware raising unresolvable dependency on Api class #284