aboutsummaryrefslogtreecommitdiffstats
path: root/src/web
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2025-04-13 15:28:23 -0500
committerGitHub <noreply@github.com>2025-04-13 15:28:23 -0500
commit7b99d3339154972eed0f04beef5a91678e5a0efb (patch)
tree917bccf09a38579025eaafa709819d5a524ff299 /src/web
parentf63238c38087bcc26fd9b47c3300e4bc4b55d0f9 (diff)
parent951b65d273fd4dcfe1508aabf2b5b4e833ecc0fa (diff)
downloadslskd-7b99d3339154972eed0f04beef5a91678e5a0efb.tar.gz
Merge pull request #1328 from slskd/bugfix
Fix cryptic message if a remote client doesn't return any files when directory contents are requested
Diffstat (limited to 'src/web')
-rw-r--r--src/web/src/components/Search/Response.jsx54
1 files changed, 33 insertions, 21 deletions
diff --git a/src/web/src/components/Search/Response.jsx b/src/web/src/components/Search/Response.jsx
index f665c816..0d94ee8c 100644
--- a/src/web/src/components/Search/Response.jsx
+++ b/src/web/src/components/Search/Response.jsx
@@ -83,30 +83,42 @@ 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,
- });
+ 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];
- const theRootDirectory = allDirectories?.[0];
- const { files, name } = theRootDirectory;
+ // some clients might send an empty response for some reason
+ if (!theRootDirectory) {
+ throw new Error('No directories were included in the response');
+ }
- // 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,
- }));
+ 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 } });
+ oldTree[name] = fixedFiles;
+ this.setState({ tree: { ...oldTree } });
+ } catch (error) {
+ throw new Error(`Failed to process directory response: ${error}`, {
+ cause: error,
+ });
+ }
} catch (error) {
console.error(error);
toast.error(error?.response?.data ?? error?.message ?? error);