Error handling in _delete_scan(), which is now handled in GUI main.js
This commit is contained in:
parent
0e3c71b958
commit
19d72bef1c
2 changed files with 27 additions and 17 deletions
|
|
@ -829,7 +829,7 @@ class SmartScanThing(Thing):
|
||||||
404: {"description": "Scan not found"},
|
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.
|
"""Delete all files from a scan.
|
||||||
|
|
||||||
This endpoint allows scans to be deleted from disk.
|
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)
|
path = os.path.join(self.base_scan_dir, scan_name)
|
||||||
if not os.path.isdir(path):
|
if not os.path.isdir(path):
|
||||||
print(f"can't find {path}")
|
print(f"can't find {path}")
|
||||||
raise HTTPException(404, "Scan not found")
|
raise HTTPException(400, "Scan not found")
|
||||||
shutil.rmtree(path)
|
result = self._delete_scan(path, logger)
|
||||||
|
if not result:
|
||||||
|
raise HTTPException(400, "Couldn't delete scan, check log for details")
|
||||||
|
|
||||||
@fastapi_endpoint(
|
@fastapi_endpoint(
|
||||||
"delete",
|
"delete",
|
||||||
|
|
@ -852,12 +854,19 @@ class SmartScanThing(Thing):
|
||||||
Use with extreme caution.
|
Use with extreme caution.
|
||||||
"""
|
"""
|
||||||
for scan in self.scans:
|
for scan in self.scans:
|
||||||
try:
|
self.delete_scan(scan.name, logger)
|
||||||
self.delete_scan(scan.name)
|
|
||||||
except PermissionError:
|
@thing_action
|
||||||
logger.warning(
|
def _delete_scan(self, scan_path, logger: InvocationLogger) -> bool:
|
||||||
f"Could not delete scan {scan.name}. Check folder permissions"
|
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
|
@property
|
||||||
def latest_preview_stitch_path(self):
|
def latest_preview_stitch_path(self):
|
||||||
|
|
@ -1168,9 +1177,4 @@ class SmartScanThing(Thing):
|
||||||
]
|
]
|
||||||
|
|
||||||
if len(image_list) == 0:
|
if len(image_list) == 0:
|
||||||
try:
|
self.delete_scan(scan.name)
|
||||||
self.delete_scan(scan.name)
|
|
||||||
except PermissionError:
|
|
||||||
logger.warning(
|
|
||||||
f"Could not delete scan {scan.name}. Check folder permissions"
|
|
||||||
)
|
|
||||||
|
|
|
||||||
|
|
@ -144,10 +144,16 @@ Vue.mixin({
|
||||||
if (error.response) {
|
if (error.response) {
|
||||||
// If the response is a nicely formatted JSON response from the server
|
// If the response is a nicely formatted JSON response from the server
|
||||||
if (error.response.data.message) {
|
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
|
// 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 we have an error object with a message, use that
|
||||||
if (error.message) return `${error.message}`;
|
if (error.message) return `${error.message}`;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue