Skip to content

Commit

Permalink
Weno better error handling from fetches (#7408)
Browse files Browse the repository at this point in the history
- this needs a rewrite but maybe later
  • Loading branch information
sjpadgett committed Apr 25, 2024
1 parent a7a58d3 commit 548db01
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
Expand Up @@ -85,7 +85,7 @@ function downloadWenoPrescriptionLog(): void
}

$logSync = new LogProperties();
if (!$logSync->logSync()) {
if (!$logSync->logSync('background')) {
error_log("Background services failed for prescription log.");
}
}
Expand Down
Expand Up @@ -139,7 +139,7 @@ public function logReview()
/**
* @throws Exception
*/
public function logSync()
public function logSync($tasked = 'background')
{
$wenoLog = new WenoLogService();
$provider_info['email'] = $this->weno_admin_email;
Expand Down Expand Up @@ -167,9 +167,20 @@ public function logSync()
if ($isError['is_error']) {
$error = $isError['messageText'];
error_log('Prescription download failed: ' . errorLogEscape($error));
$wenoLog->insertWenoLog("prescription", "Invalid Prescriber Credentials Hint:see previous errors.");
EventAuditLogger::instance()->newEvent("prescriptions_log", $_SESSION['authUser'], $_SESSION['authProvider'], 0, ($error));
die(js_escape($error));
// if background task then return false
if ($tasked == 'background') {
$wenoLog->insertWenoLog("prescription", "Invalid Prescriber Credentials Background Service.");
return false;
}
if ($tasked == 'downloadLog') {
$wenoLog->insertWenoLog("prescription", "Invalid Prescriber Credentials User Download.");
echo(js_escape($error));
exit;
}
$wenoLog->insertWenoLog("prescription", "Invalid Prescriber Credentials Hint:see previous errors.");
echo(js_escape($error));
return false;
}
$wenoLog->insertWenoLog("prescription", "Success");
} else {
Expand Down
Expand Up @@ -26,7 +26,8 @@

$logProperties = new LogProperties();
try {
$result = $logProperties->logSync();
$task = $_REQUEST['key'] ?? $_POST['key'] ?? '';
$result = $logProperties->logSync($task);
} catch (Exception $e) {
$result = false;
error_log('Error syncing log: ' . errorLogEscape($e->getMessage()));
Expand Down

0 comments on commit 548db01

Please sign in to comment.