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

Remove dep with symfony/http-kernel #135

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jissereitsma
Copy link

As mentioned in #107 there is an undocumented dependency with symfony/http-kernel only for an exception that is thrown. The HttpException (https://github.com/symfony/http-kernel/blob/6.3/Exception/HttpException.php) actually inherits from \RuntimeException. This PR simply just removes the dep and throws the RuntimeException as is. Nothing fancy.

Additional comment, the reason why this issue got started is that the symfony/http-foundation package (which is a requirement for Magewire) has a require-dev dep with symfony/http-kernel (https://github.com/symfony/http-foundation/blob/6.3/composer.json#L29). If composer is installed in dev env, then this problem does not occur.

@@ -71,7 +71,7 @@ public function execute(): Json
try {
$request = $this->httpFactory->createRequest($this->request->getParams())->isSubsequent(true);
} catch (LocalizedException $exception) {
throw new HttpException(400);
throw new RuntimeException(400);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure this should be merged into the core. \RuntimeException's first arg requires a message and the second a exception code. The reason having the HttpException is not having to pass in each status message for simple 400, 404, 503 etc. Those are all default and will be rendered in the frontend.

Also, having the right status code is also important in the frontend.

Is there something I'm overlooking?

Copy link
Author

Choose a reason for hiding this comment

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

No, you spotted a mistake I made. Having the HTTP status code available is indeed a requirement I missed. However, adding a composer package for this seems a bit much. One option could be to simply create a duplicate HttpException class in the magewire package (and then drop the dependency with symfony/http-kernel). Another option could be to simply refactor the code in the controller a bit further - the HttpException class is used only once as an argument to throwException($exception). The HTTP status code could easily be turned into an optional second argument (throwException($exception, $statusCode = null). Which option do you think is better? Happy to refactor this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants