diff options
| author | JP Dillingham <jp@dillingham.me> | 2025-04-13 15:13:06 -0500 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2025-04-13 15:13:06 -0500 |
| commit | c08ac7740ac2bd0b7013a4ed7af107117f0dee76 (patch) | |
| tree | 6010f73c406c9c8191bc5dc25e550ded01f4592f /src/web | |
| parent | f63238c38087bcc26fd9b47c3300e4bc4b55d0f9 (diff) | |
| download | slskd-c08ac7740ac2bd0b7013a4ed7af107117f0dee76.tar.gz | |
improve directory response error handling
Diffstat (limited to 'src/web')
| -rw-r--r-- | src/web/src/components/Search/Response.jsx | 45 |
1 files changed, 31 insertions, 14 deletions
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); |
