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

Returning error responses from customer handler #43

Open
wireblue opened this issue Oct 29, 2015 · 3 comments
Open

Returning error responses from customer handler #43

wireblue opened this issue Oct 29, 2015 · 3 comments

Comments

@wireblue
Copy link
Contributor

Hi all,

Not sure if this is incorrect usage or a bug, but I'm getting errors when returning error response from my customer handlers.

Example:

public function handleGet(ApiRequest $request)
{
    // ...
    return new ApiErrorResponse(404, 404, "Product doesn't exist.");
}

Because Handler.php is only looking for instances of "Response" (on Line 84), not ErrorResponse or MultiErrorResponse, it trips up when it tries to load the (non-existent) models.

I'd be happy to submit a simple PR to check for the other two response types, but I didn't know if this was the best way to go about it. Should ErrorResponse and MultiErrorResponse be inheriting from Response instead, or am I "doing it wrong"?

Thoughts?

Kyle

@egeriis
Copy link
Owner

egeriis commented Oct 29, 2015

Really depends on how your controller handles the Handler return value.

If you have a look at the example, you can see that JsonApi\Exceptions are caught and handled appropriately, but it's up to you to implement this logic.

@wireblue
Copy link
Contributor Author

For the me the problem is occuring when I return an ErrorResponse object from my custom handler (eg. ProductsHandler.php) to this project's "Handler.php". This occurs within the "fulfillRequest" method. It hasn't yet returned back to the controller yet, so I'm unable to deal with it there.

Are you suggesting that I should implement my own version of "fulfillRequest", or bypass it completely in my controller?

@wireblue
Copy link
Contributor Author

wireblue commented Dec 2, 2015

If it helps anyone else I ended up creating my own "BaseHandler" which extended the \EchoIt\JsonApi\Handler. I changed the "fulfillRequest" to suit my needs and updated my other handlers to extend from my new "BaseHandler".

I feel a fix to the \EchoIt\JsonApi\Handler would be more ideal, so I will leave this issue open and to the discretion of the repo maintainer.

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