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

[RFC]: 'delete.post' event isn't triggered for custom Response for DELETE request #23

Open
darckking opened this issue Jul 7, 2021 · 0 comments
Labels

Comments

@darckking
Copy link

RFC

Q A
Proposed Version(s) 1.6.2
BC Break? No

Laminas\ApiTools\Rest\RestController::delete($id)
If I return own Laminas\Http\Response on line 443 as $result, the event 'delete.post' won't be triggered.

        try {
            $result = $this->getResource()->delete($id);
        } catch (Throwable $e) {
            return $this->createApiProblemFromException($e);
        } catch (Exception $e) {
            return $this->createApiProblemFromException($e);
        }

        $result = $result ?: new ApiProblem(422, 'Unable to delete entity.');

        if ($this->isPreparedResponse($result)) {
            return $result;
        }

        $response = $this->getResponse();
        $response->setStatusCode(204);

        $events->trigger('delete.post', $this, ['id' => $id]);

        return $response;

Scenario
Resource deletion leads to change of other resources and client must be notified about it. So we return 200 with response body. But if other modules listen for 'delete.post' and perform extra actions - they won't be notified about resource deletion.

Suggestion
Check if $result is instance of Laminas\Http\Response separately from ApiProblem / ApiProblemResponse and trigger 'delete.post' before returning it.

@darckking darckking added the RFC label Jul 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant