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

Repository delete() ModelNotFoundException is never thrown #750

Open
m0nclous opened this issue Mar 7, 2024 · 0 comments
Open

Repository delete() ModelNotFoundException is never thrown #750

m0nclous opened this issue Mar 7, 2024 · 0 comments

Comments

@m0nclous
Copy link

m0nclous commented Mar 7, 2024

Apiato Version

12.4.1

PHP Version

8.3

Database Driver & Version

No response

Description

Exception ModelNotFoundException is never thrown in this method, but the phpdoc says it can be thrown.

/**
* Delete a model by its primary key or throw an exception.
*
* @param int|string $id
*
* @throws ModelNotFoundException
* @throws DeleteResourceFailedException
*/
public function delete($id): bool
{
try {
return (bool) parent::delete($id);
} catch (\Exception) {
throw new DeleteResourceFailedException();
}
}

Maybe it makes sense to catch ModelNotFoundException and in this case return false from the delete function (similar to other methods that return empty data)?

Or catch ModelNotFoundException and throw NotFoundException to indicate that the requested model is not available for deletion.

namespace App\Ship\Exceptions;
use App\Ship\Parents\Exceptions\Exception;
use Symfony\Component\HttpFoundation\Response;
class NotFoundException extends Exception
{
protected $code = Response::HTTP_NOT_FOUND;
protected $message = 'The requested resource could not be found.';
}

Steps To Reproduce

app(UserRepository::class)->delete(9999999);
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

1 participant