From f780c19288cb0d3e67cda6c3d55cc296429702ef Mon Sep 17 00:00:00 2001 From: Mark Unwin Date: Fri, 2 Feb 2024 10:24:05 +1000 Subject: [PATCH] More gracefully handle no response->data from a Report in the Reports controller. --- app/Controllers/Reports.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/Controllers/Reports.php b/app/Controllers/Reports.php index cde95f099..f3abb1761 100644 --- a/app/Controllers/Reports.php +++ b/app/Controllers/Reports.php @@ -66,9 +66,9 @@ public function execute($id) $breadcrumb = new stdClass(); $breadcrumb->url = url_to('reportsExecute', $this->resp->meta->id); - $breadcrumb->name = $this->resp->meta->name ; + $breadcrumb->name = (!empty($this->resp->meta->name)) ? $this->resp->meta->name : ''; $this->resp->meta->breadcrumbs[] = $breadcrumb; - $this->resp->data = format_data($this->resp->data, 'devices'); + $this->resp->data = (!empty($this->resp->data)) ? format_data($this->resp->data, 'devices') : array(); $this->resp->meta->total = count($this->resp->data); $this->resp->meta->filtered = count($this->resp->data); @@ -83,7 +83,11 @@ public function execute($id) return true; } if (empty($this->resp->data)) { - \Config\Services::session()->setFlashdata('error', 'No data returned when running report.'); + if (empty($this->resp->errors)) { + \Config\Services::session()->setFlashdata('error', 'No data returned when running report.'); + } else { + \Config\Services::session()->setFlashdata('error', $this->resp->errors); + } return redirect()->route('devicesCollection'); } if ($this->resp->meta->filtered === $this->resp->meta->limit) {