diff --git a/app/View/Label.php b/app/View/Label.php index a7c6641a5..e3f0ba724 100644 --- a/app/View/Label.php +++ b/app/View/Label.php @@ -38,7 +38,6 @@ class Label implements View $settings = $this->data->get('settings'); $assets = $this->data->get('assets'); $offset = $this->data->get('offset'); - $template = LabelModel::find($settings->label2_template); // If disabled, pass to legacy view if ((!$settings->label2_enable)) { @@ -49,11 +48,24 @@ class Label implements View ->with('count', $this->data->get('count')); } - if ($template === null) { - throw new \UnexpectedValueException('Template is null.'); + try { + $template = LabelModel::find($settings->label2_template); + + if ($template === null) { + throw new \UnexpectedValueException('Template is null.'); + } + + $template->validate(); + } catch (\UnexpectedValueException $e) { + + \Log::error('Validation failed: ' . $e->getMessage()); + + } catch (\Throwable $e) { + + \Log::error('An unexpected error occurred: ' . $e->getMessage()); + } - $template->validate(); $pdf = new TCPDF( $template->getOrientation(),