Skip to content

Commit

Permalink
add a try catch around template validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Godmartinz committed Jan 8, 2025
1 parent ce7a8ad commit f4e6967
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions app/View/Label.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public function render(callable $callback = null)
$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)) {
Expand All @@ -49,11 +48,24 @@ public function render(callable $callback = null)
->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(),
Expand Down

0 comments on commit f4e6967

Please sign in to comment.