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

Allow ItemDataProvider to throw more exceptions #455

Merged
merged 1 commit into from Mar 16, 2016

Conversation

theofidry
Copy link
Contributor

Q A
Bug fix? no
New feature? yes
BC breaks? yes
Deprecations? no
Tests pass? yes
Fixed tickets none
License MIT
Doc PR none

I find the current very restrictive: it only allows an item provider to throw exceptions when it does not support the class or received an incorrect value. As the responsibility of an item provider is to retrieve an item from the persistent layer, it looks to me that there could be all kind of other problems: could not establish a connection with the persistence layer, the item could not be retrieve, etc.

If someone wants to add a custom provider implementing this interface and have to face one of the situation above, he will have little choice but to return null. IMO, this is not helpful as the null value should be used here for when no item was found. If there was an error while trying to retrieve this item, an exception should be fired. Hence my change in the interface.

@@ -22,8 +23,6 @@
interface ItemDataProviderInterface
{
/**
* Retrieves an item.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed comment as is not very helpful IMO: we already have this description in the interface doc and the method name is quite explicit already.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we already have this description in the interface

I don't get it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The interface description is "Retrieves items from a persistence layer.", so having "Retrieves an item." for this interface getItem() method description looks... obvious.

That being said it's just a method description... No strong feelings here :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm for keeping it, it will produce a nicer HTML PHPDoc.

* @param string $resourceClass
* @param string|null $operationName
* @param int|string $id
* @param bool $fetchData
*
* @throws ResourceClassNotSupportedException
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would keep this one explicitly because this is a case that must be handled in many cases (for others, it's fine to let them be converted to an error displayed to the end user).

@theofidry
Copy link
Contributor Author

Updated, also apply those changes to CollectionDataProviderInterface

@theofidry
Copy link
Contributor Author

ping @api-platform/core-team

@sroze
Copy link
Contributor

sroze commented Mar 16, 2016

👍

theofidry added a commit that referenced this pull request Mar 16, 2016
Allow ItemDataProvider to throw more exceptions
@theofidry theofidry merged commit b85c30b into api-platform:master Mar 16, 2016
@theofidry theofidry deleted the item-data-retriever branch March 16, 2016 11:47
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

Successfully merging this pull request may close these issues.

None yet

3 participants