From 1388e1379512ddfd4d5bfbecaac2a598dd85151c Mon Sep 17 00:00:00 2001 From: Joel Marcey Date: Fri, 16 Feb 2018 19:16:38 -0800 Subject: [PATCH] Don't throw if a doc hasn't been versioned yet (#455) Instead of throwing, return `null` because that means we have a new doc in our versioning sequence (Also, cleaned up a bit of code as I researched this) Partial Fix To #450 --- lib/server/versionFallback.js | 4 +--- lib/version.js | 3 +-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/server/versionFallback.js b/lib/server/versionFallback.js index ddd1df8494..e6dac97705 100644 --- a/lib/server/versionFallback.js +++ b/lib/server/versionFallback.js @@ -133,9 +133,7 @@ files.forEach(file => { // what the requested version is function docVersion(id, req_version) { if (!available[id]) { - throw new Error( - `Document with id '${id}' was requested but no document with that id could be located.` - ); + return null; } // iterate through versions until a version less than or equal to the requested // is found, then check if that version has an available file to use diff --git a/lib/version.js b/lib/version.js index 4df180de19..0eefc98345 100755 --- a/lib/version.js +++ b/lib/version.js @@ -96,8 +96,7 @@ files.forEach(file => { metadata.original_id = metadata.id; metadata.id = 'version-' + version + '-' + metadata.id; - const targetFile = - CWD + '/versioned_docs/version-' + version + '/' + path.basename(file); + const targetFile = versionFolder + '/' + path.basename(file); fs.writeFileSync(targetFile, makeHeader(metadata) + rawContent, 'utf8'); });