From c08ac7740ac2bd0b7013a4ed7af107117f0dee76 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 13 Apr 2025 15:13:06 -0500 Subject: improve directory response error handling --- src/web/src/components/Search/Response.jsx | 45 ++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 14 deletions(-) (limited to 'src/web') diff --git a/src/web/src/components/Search/Response.jsx b/src/web/src/components/Search/Response.jsx index f665c816..079b91ba 100644 --- a/src/web/src/components/Search/Response.jsx +++ b/src/web/src/components/Search/Response.jsx @@ -91,22 +91,39 @@ class Response extends Component { username, }); - const theRootDirectory = allDirectories?.[0]; - const { files, name } = theRootDirectory; + // todo: deleteme + console.log('allDirectories', allDirectories); + console.log('allDirectoriesJson', JSON.stringify(allDirectories)); - // the api returns file names only, so we need to prepend the directory - // to make it look like a search result. we also need to preserve - // any file selections, so check the old files and assign accordingly - const fixedFiles = files.map((file) => ({ - ...file, - filename: `${directory}\\${file.filename}`, - selected: - oldFiles.find((f) => f.filename === `${directory}\\${file.filename}`) - ?.selected ?? false, - })); + try { + const theRootDirectory = allDirectories?.[0]; + + if (!theRootDirectory) { + throw new Error('No directories were included in the response'); + } - oldTree[name] = fixedFiles; - this.setState({ tree: { ...oldTree } }); + const { files, name } = theRootDirectory; + + // the api returns file names only, so we need to prepend the directory + // to make it look like a search result. we also need to preserve + // any file selections, so check the old files and assign accordingly + const fixedFiles = files.map((file) => ({ + ...file, + filename: `${directory}\\${file.filename}`, + selected: + oldFiles.find( + (f) => f.filename === `${directory}\\${file.filename}`, + )?.selected ?? false, + })); + + oldTree[name] = fixedFiles; + this.setState({ tree: { ...oldTree } }); + } catch (error) { + throw new Error( + `Failed to process the requested folder response: ${error}`, + { cause: error }, + ); + } } catch (error) { console.error(error); toast.error(error?.response?.data ?? error?.message ?? error); -- cgit v1.2.3 From 951b65d273fd4dcfe1508aabf2b5b4e833ecc0fa Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 13 Apr 2025 15:20:53 -0500 Subject: shorten message --- src/web/src/components/Search/Response.jsx | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) (limited to 'src/web') diff --git a/src/web/src/components/Search/Response.jsx b/src/web/src/components/Search/Response.jsx index 079b91ba..0d94ee8c 100644 --- a/src/web/src/components/Search/Response.jsx +++ b/src/web/src/components/Search/Response.jsx @@ -83,21 +83,17 @@ class Response extends Component { const oldTree = { ...this.state.tree }; const oldFiles = oldTree[directory]; - // some clients might send more than one directory in the response, - // if the requested directory contains subdirectories. the root directory - // is always first, and for now we'll only display the contents of that. - const allDirectories = await getDirectoryContents({ - directory, - username, - }); - - // todo: deleteme - console.log('allDirectories', allDirectories); - console.log('allDirectoriesJson', JSON.stringify(allDirectories)); - try { + // some clients might send more than one directory in the response, + // if the requested directory contains subdirectories. the root directory + // is always first, and for now we'll only display the contents of that. + const allDirectories = await getDirectoryContents({ + directory, + username, + }); const theRootDirectory = allDirectories?.[0]; + // some clients might send an empty response for some reason if (!theRootDirectory) { throw new Error('No directories were included in the response'); } @@ -119,10 +115,9 @@ class Response extends Component { oldTree[name] = fixedFiles; this.setState({ tree: { ...oldTree } }); } catch (error) { - throw new Error( - `Failed to process the requested folder response: ${error}`, - { cause: error }, - ); + throw new Error(`Failed to process directory response: ${error}`, { + cause: error, + }); } } catch (error) { console.error(error); -- cgit v1.2.3