Improve error handling for unavailable network shares
- Add OSError/PermissionError handling in browse endpoint - Return 503 status code when folders are temporarily unavailable - Display user-friendly error messages in the UI - Enhance error logging with exception type information Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -254,8 +254,15 @@ async def browse(
|
|||||||
raise HTTPException(status_code=400, detail=str(e))
|
raise HTTPException(status_code=400, detail=str(e))
|
||||||
except FileNotFoundError as e:
|
except FileNotFoundError as e:
|
||||||
raise HTTPException(status_code=404, detail=str(e))
|
raise HTTPException(status_code=404, detail=str(e))
|
||||||
|
except (OSError, PermissionError) as e:
|
||||||
|
# Network share unavailable or access denied
|
||||||
|
logger.warning(f"Folder temporarily unavailable: {e}")
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=503,
|
||||||
|
detail=f"Folder is temporarily unavailable. It may be a network share that is not accessible at the moment."
|
||||||
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Error browsing directory: {e}")
|
logger.error(f"Error browsing directory (type: {type(e).__name__}): {e}")
|
||||||
raise HTTPException(status_code=500, detail="Failed to browse directory")
|
raise HTTPException(status_code=500, detail="Failed to browse directory")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1579,7 +1579,14 @@ async function browsePath(folderId, path, offset = 0, nocache = false) {
|
|||||||
{ headers: { 'Authorization': `Bearer ${token}` } }
|
{ headers: { 'Authorization': `Bearer ${token}` } }
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!response.ok) throw new Error('Failed to browse path');
|
if (!response.ok) {
|
||||||
|
let errorMsg = 'Failed to browse path';
|
||||||
|
if (response.status === 503) {
|
||||||
|
const errorData = await response.json().catch(() => ({}));
|
||||||
|
errorMsg = errorData.detail || 'Folder is temporarily unavailable (network share not accessible)';
|
||||||
|
}
|
||||||
|
throw new Error(errorMsg);
|
||||||
|
}
|
||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
currentPath = data.current_path;
|
currentPath = data.current_path;
|
||||||
@@ -1602,7 +1609,8 @@ async function browsePath(folderId, path, offset = 0, nocache = false) {
|
|||||||
saveLastBrowserPath(folderId, currentPath);
|
saveLastBrowserPath(folderId, currentPath);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error browsing path:', error);
|
console.error('Error browsing path:', error);
|
||||||
showToast(t('browser.error_loading'), 'error');
|
const errorMsg = error.message || t('browser.error_loading');
|
||||||
|
showToast(errorMsg, 'error');
|
||||||
clearBrowserGrid();
|
clearBrowserGrid();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user