From b9d349e00df731e80ccb4fbdf9d3b94b22e217bd Mon Sep 17 00:00:00 2001
From: Arjun Kumar <25382-Manav@users.noreply.drupalcode.org>
Date: Sun, 10 Nov 2024 10:25:59 +0000
Subject: [PATCH] Resolve #3485274 "Task delete functionality"

---
 src/Form/DeleteTaskForm.php | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/src/Form/DeleteTaskForm.php b/src/Form/DeleteTaskForm.php
index 323dda1..2ac2151 100644
--- a/src/Form/DeleteTaskForm.php
+++ b/src/Form/DeleteTaskForm.php
@@ -5,6 +5,7 @@ namespace Drupal\todoist_api\Form;
 use Drupal\Core\Form\ConfirmFormBase;
 use Drupal\Core\Form\FormStateInterface;
 use Drupal\Core\Url;
+use GuzzleHttp\Exception\RequestException;
 
 /**
  * Defines a confirmation form to confirm deletion of something by id.
@@ -40,11 +41,18 @@ class DeleteTaskForm extends ConfirmFormBase {
     // @todo: Do the deletion.
     $uri = 'tasks';
     $content_id = $this->id;
-    $response = \Drupal::service('todoist_api.client')->delete($uri, $content_id);
-    if($response):
-      $this->messenger()->addStatus($this->t('A task has been deleted.'));
+    try{
+      $response = \Drupal::service('todoist_api.client')->delete($uri, $content_id);
+      if($response):
+        $this->messenger()->addStatus($this->t('A task has been deleted.'));
+        $form_state->setRedirect('todoist_api.taskscontroller');
+      endif;
+    } catch( RequestException $exception) {
+      \Drupal::logger('error_rest_client')->notice($exception->getMessage());
+      $form_state->setErrorByName('task', $this->t('Application error. Please check your logs.'));
       $form_state->setRedirect('todoist_api.taskscontroller');
-    endif;
+    }
+
   }
 
   /**
-- 
GitLab