From 27b89ed59d5de29a3f9e5b89988070c8f09af73f Mon Sep 17 00:00:00 2001
From: ale <ale@incal.net>
Date: Fri, 17 Nov 2023 15:41:43 +0000
Subject: [PATCH] Improve error checking on calls to wp-mat-server

Addresses issue #1.
---
 wp-mat.php | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/wp-mat.php b/wp-mat.php
index af56c19..0f61ed6 100644
--- a/wp-mat.php
+++ b/wp-mat.php
@@ -3,7 +3,7 @@
  * Plugin Name: wp-mat
  * Plugin URI: https://git.autistici.org/noblogs/wp-mat
  * Description: Process uploaded files through MAT
- * Version: 0.1.2
+ * Version: 0.1.4
  * Author: Autistici/Inventati
  * Author URI: https://www.autistici.org/
  * License: MIT
@@ -38,7 +38,8 @@ class WP_Mat {
     }
 
     // Make a POST request to the MAT service with the uploaded file and
-    // store the results into '$output_path'.
+    // store the results into '$output_path'. Returns true on success,
+    // false on any error.
     function issue_cleanup_request($path, $mimetype, $output_path) {
         $upfile = new CURLFile($path, $mimetype, 'input');
 
@@ -59,6 +60,16 @@ class WP_Mat {
 
         $ret = curl_exec($curl);
 
+        if ($ret === false) {
+            error_log("wp-mat: curl error: ".curl_error($curl));
+        } else {
+            $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
+            if ($status != 200) {
+                error_log("wp-mat: curl error: server returned HTTP status ".$status);
+                $ret = false;
+            }
+        }
+
         fclose($fp);
         curl_close($curl);
 
-- 
GitLab