Skip to content

The exception handler is overriden if calling $model->getFullUrl() on the frontend #2607

@Tofandel

Description

@Tofandel

The method getFullUrl has an unexpected side effect, because it constructs the controller of the model which binds a different exception handler even if the request doesn't originate from twill

This is problematic as then exceptions are not rendering as expected or reported to sentry

twill/src/Models/Model.php

Lines 185 to 197 in 6d02239

public function getFullUrl(): string
{
if (! method_exists($this, 'getSlug')) {
return '#';
}
// @phpstan-ignore-next-line
if (method_exists($this, 'getUrlWithoutSlug') && $this->urlWithoutSlug) {
return rtrim($this->urlWithoutSlug, '/') . '/' . $this->getSlug();
}
try {
$controller = getModelController($this);

public function __construct()
{
if (Config::get('twill.bind_exception_handler', true)) {
App::singleton(ExceptionHandler::class, TwillHandler::class);
}

(And yes I spent 3 hours trying to figure out why my 404 pages were rendering like this in production
image instead of with my custom view, long story short I have a menu that uses a Page model and gets the url of those pages using getFullUrl)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions