diff --git a/src/openflexure_microscope_server/things/smart_scan.py b/src/openflexure_microscope_server/things/smart_scan.py index 2a58ba64..a3c11eed 100644 --- a/src/openflexure_microscope_server/things/smart_scan.py +++ b/src/openflexure_microscope_server/things/smart_scan.py @@ -829,7 +829,7 @@ class SmartScanThing(Thing): 404: {"description": "Scan not found"}, }, ) - def delete_scan(self, scan_name: str) -> None: + def delete_scan(self, scan_name: str, logger: InvocationLogger) -> None: """Delete all files from a scan. This endpoint allows scans to be deleted from disk. @@ -837,8 +837,10 @@ class SmartScanThing(Thing): path = os.path.join(self.base_scan_dir, scan_name) if not os.path.isdir(path): print(f"can't find {path}") - raise HTTPException(404, "Scan not found") - shutil.rmtree(path) + raise HTTPException(400, "Scan not found") + result = self._delete_scan(path, logger) + if not result: + raise HTTPException(400, "Couldn't delete scan, check log for details") @fastapi_endpoint( "delete", @@ -852,12 +854,19 @@ class SmartScanThing(Thing): Use with extreme caution. """ for scan in self.scans: - try: - self.delete_scan(scan.name) - except PermissionError: - logger.warning( - f"Could not delete scan {scan.name}. Check folder permissions" - ) + self.delete_scan(scan.name, logger) + + @thing_action + def _delete_scan(self, scan_path, logger: InvocationLogger) -> bool: + try: + shutil.rmtree(scan_path) + return True + except Exception as e: + logger.warning( + "Attempted to delete scan " + scan_path + ", which failed." + " Server sent response" + str(e) + ) + return False @property def latest_preview_stitch_path(self): @@ -1168,9 +1177,4 @@ class SmartScanThing(Thing): ] if len(image_list) == 0: - try: - self.delete_scan(scan.name) - except PermissionError: - logger.warning( - f"Could not delete scan {scan.name}. Check folder permissions" - ) + self.delete_scan(scan.name) diff --git a/webapp/src/main.js b/webapp/src/main.js index c95e5869..ed49dbc1 100644 --- a/webapp/src/main.js +++ b/webapp/src/main.js @@ -144,10 +144,16 @@ Vue.mixin({ if (error.response) { // If the response is a nicely formatted JSON response from the server if (error.response.data.message) { - return `${error.response.status}: ${error.response.data.message}`; + return `${error.response.data.message}`; + } + if (error.response.data.detail) { + return `${error.response.data.detail}`; } // If the response is just some generic error response - return `${error.response.status}: ${error.response.data}`; + if (error.response.data){ + return `${error.response.data}`; + } + return `${error.response}`; } // If we have an error object with a message, use that if (error.message) return `${error.message}`;