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
This commit is contained in:
Joel Marcey 2018-02-16 19:16:38 -08:00 committed by GitHub
parent 5dd8b7334b
commit 1388e13795
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 5 deletions

View file

@ -133,9 +133,7 @@ files.forEach(file => {
// what the requested version is // what the requested version is
function docVersion(id, req_version) { function docVersion(id, req_version) {
if (!available[id]) { if (!available[id]) {
throw new Error( return null;
`Document with id '${id}' was requested but no document with that id could be located.`
);
} }
// iterate through versions until a version less than or equal to the requested // 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 // is found, then check if that version has an available file to use

View file

@ -96,8 +96,7 @@ files.forEach(file => {
metadata.original_id = metadata.id; metadata.original_id = metadata.id;
metadata.id = 'version-' + version + '-' + metadata.id; metadata.id = 'version-' + version + '-' + metadata.id;
const targetFile = const targetFile = versionFolder + '/' + path.basename(file);
CWD + '/versioned_docs/version-' + version + '/' + path.basename(file);
fs.writeFileSync(targetFile, makeHeader(metadata) + rawContent, 'utf8'); fs.writeFileSync(targetFile, makeHeader(metadata) + rawContent, 'utf8');
}); });