Skip to content

Commit

Permalink
add error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Wu authored and Matthew Wu committed Jan 19, 2024
1 parent 681d3f6 commit dd9303b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/IndexingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ public function delete(string $uri) {
$config = \Drupal::config('triplestore_indexer.settings');
$server = $config->get("server_url");
$namespace = $config->get("namespace");
$username = $config->get("admin_username");
$password = $config->get("admin_password");

$opts = [

Expand All @@ -158,12 +160,28 @@ public function delete(string $uri) {
CURLOPT_POSTFIELDS => "",
CURLOPT_HTTPHEADER => [
'Content-type: text/plain',
'Authorization: Basic ' . base64_encode("$username:$password"),
],
];
curl_setopt_array($curl, $opts);

$response = curl_exec($curl);

// Check for cURL errors
if ($response === false) {
$error_message = curl_error($curl);
curl_close($curl);
throw new \Exception("cURL error: $error_message");
}

// Check HTTP status code for errors
$http_status_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);

if ($http_status_code < 200 || $http_status_code >= 300) {
throw new \Exception("HTTP error: $http_status_code");
}

return $response;
}

Expand Down
13 changes: 12 additions & 1 deletion src/Plugin/AdvancedQueue/JobType/TriplestoreIndexJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,18 @@ public function process(Job $job) {
$type = str_replace("_", "/", $payload['type']);

$urijld = "<$base_url/$type/$nid" . '?_format=jsonld>';
$response = $service->delete($urijld);

try {
$response = $service->delete($urijld);
} catch (\Exception $e) {
if ($e->getCode() == 401) {
// Retry with authorization headers if 401 Unauthorized
$response = $service->delete($urijld);
} else {
// Handle other exceptions
throw $e;
}
}
$result = simplexml_load_string($response);

if ($result['modified'] <= 0) {
Expand Down

0 comments on commit dd9303b

Please sign in to comment.