From 06f7061acf7c949fe3b85dc51caebfb5d072c93f Mon Sep 17 00:00:00 2001 From: Nell Hardcastle Date: Thu, 4 Jan 2024 09:46:29 -0800 Subject: [PATCH] fix(api): Prevent crash when tree is requested with no children --- packages/openneuro-server/src/handlers/datalad.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/openneuro-server/src/handlers/datalad.ts b/packages/openneuro-server/src/handlers/datalad.ts index 4490e5b77..1982f4711 100644 --- a/packages/openneuro-server/src/handlers/datalad.ts +++ b/packages/openneuro-server/src/handlers/datalad.ts @@ -29,7 +29,10 @@ export const getFile = async (req, res) => { if (level == pathComponents.slice(-1)) { file = files.find((f) => !f.directory && f.filename === level) } else { - tree = files.find((f) => f.directory && f.filename === level).id + // This tree may exist but have no children + if (files) { + tree = files.find((f) => f.directory && f.filename === level).id + } } } catch (err) { // ConnectTimeoutError is Node/Undici and TimeoutError is the standard DOMException name