Skip to content

Commit

Permalink
Improve error handling of JSON list creation.
Browse files Browse the repository at this point in the history
  • Loading branch information
emaijala committed Nov 11, 2023
1 parent a3d6c2a commit 4034dda
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions list.php
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ className: '<?php echo $class?>',
* @param int $companyId Company ID
* @param int $searchId Saved search ID
*
* @return void
* @return string
*/
function createJSONList(
string $strFunc,
Expand All @@ -492,19 +492,14 @@ function createJSONList(
string $listId,
int $companyId = null,
int $searchId = null
) {
): string {
$listConfig = getListConfig($strList);
if (!$listConfig) {
return;
return '{"error": "Invalid list"}';
}

if (!sesAccessLevel($listConfig['accessLevels']) && !sesAdminAccess()) {
?>
<div class="form_container">
<?php echo Translator::translate('NoAccess') . "\n"?>
</div>
<?php
return;
return '{"error": "Access denied"}';
}

$queryBuilders = createListQuery(
Expand Down Expand Up @@ -678,7 +673,7 @@ function createJSONList(
'recordsFiltered' => $filteredCount ?? $totalCount,
'data' => $records
];
return json_encode($results);
return json_encode($results, JSON_INVALID_UTF8_IGNORE) ?: '{"error": "Encode failed: ' . json_last_error_msg() . '"}';
}

/**
Expand Down

0 comments on commit 4034dda

Please sign in to comment.