Skip to content

Conversation

@Nolab0
Copy link
Member

@Nolab0 Nolab0 commented Dec 29, 2025

Close #361

When intentionally breaking the twig template:
image

@Nolab0 Nolab0 requested review from Nadil-K and supun-io December 29, 2025 17:28
Copy link
Member

@supun-io supun-io left a comment

Choose a reason for hiding this comment

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

  • add a screenshot of the frontend error UI as well

$twigTemplate = $this->twig->createTemplate($template);
return $twigTemplate->render((array)$variables);
} catch (TwigError $e) {
throw new UnprocessableEntityHttpException($e->getRawMessage());
Copy link
Member

Choose a reason for hiding this comment

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

you can't throw HttpExceptions in services. You have to either (1) simply not catch the TwigError and mark the function throwing that exception, or (2) throw a custom exception. Here, I believe (2) would work better. Then, in the Http controller where this service is used, you have to catch that and throw the Http exception.

@supun-io supun-io merged commit 217aac7 into main Jan 14, 2026
6 checks passed
@supun-io supun-io deleted the 361-twig-error-handling branch January 14, 2026 11:11
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.

Twig error handling

3 participants