From 6c569bcfba8bc8c6b34600d190183523e6e17b26 Mon Sep 17 00:00:00 2001 From: "contact@grandville.net" Date: Thu, 18 Jun 2020 14:30:51 +0200 Subject: [PATCH] Add error message in getstatus_scan response --- PatrowlEnginesUtils/PatrowlEngine.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/PatrowlEnginesUtils/PatrowlEngine.py b/PatrowlEnginesUtils/PatrowlEngine.py index 9ea75d6..5d0cd46 100644 --- a/PatrowlEnginesUtils/PatrowlEngine.py +++ b/PatrowlEnginesUtils/PatrowlEngine.py @@ -176,6 +176,8 @@ def clean_scan(self, scan_id): def getstatus_scan(self, scan_id): """Get the status of a scan identified by his 'id'.""" + + response = {} if scan_id not in self.scans.keys(): raise PatrowlEngineExceptions(1002,"scan_id '{}' not found".format(scan_id)) @@ -196,7 +198,16 @@ def getstatus_scan(self, scan_id): # update finished time if not already set self.scans[scan_id]['finished_at'] = int(time.time() * 1000) - return jsonify({"status": self.scans[scan_id]['status']}) + # if a reason is specified, replicate it in response + if 'reason' in self.scans[scan_id].keys(): + response.update({'reason': self.scans[scan_id]['reason']}) + elif 'details' in self.scans[scan_id].keys() and 'reason' in self.scans[scan_id]['details']: + response.update({'reason': self.scans[scan_id]['details']['reason']) + + response.update({'status': self.scans[scan_id]['status'], + 'finished_at': self.scans[scan_id]['finished_at']}) + + return jsonify(response) def getstatus(self):