From cb18ec2eeab93542fc8cb009f424b8227274734b Mon Sep 17 00:00:00 2001 From: Thibault Dockx <thibault.dockx@fusiondirectory.org> Date: Tue, 25 Mar 2025 11:57:08 +0000 Subject: [PATCH] :sparkles: feat(archive) - update archive request settings and improve error handling for unexpected HTTP status codes --- plugins/tasks/Archive.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/plugins/tasks/Archive.php b/plugins/tasks/Archive.php index f2bd8fb..593c99d 100644 --- a/plugins/tasks/Archive.php +++ b/plugins/tasks/Archive.php @@ -55,17 +55,15 @@ class Archive implements EndpointInterface // Set the archive endpoint and method using the same WebServiceCall object $archiveUrl = $_ENV['FUSION_DIRECTORY_API_URL'] . '/archive/user/' . rawurlencode($task['fdtasksgranulardn'][0]); - $webServiceCall->setCurlSettings($archiveUrl, [], 'POST'); // Update settings for the archive request + $webServiceCall->setCurlSettings($archiveUrl, NULL, 'POST'); // Update settings for the archive request $response = $webServiceCall->execute(); - print_r([$response]); - exit; - - if (isset($response['success']) && $response['success'] === true) { + // Check if the HTTP status code is 204 + if ($webServiceCall->getHttpStatusCode() === 204) { $result[$task['dn']]['result'] = "User successfully archived."; $this->gateway->updateTaskStatus($task['dn'], $task['cn'][0], '2'); } else { - throw new Exception("Invalid API response format"); + throw new Exception("Unexpected HTTP status code: " . $webServiceCall->getHttpStatusCode()); } } catch (Exception $e) { $result[$task['dn']]['result'] = "Error archiving user: " . $e->getMessage(); -- GitLab