[Versioning] Fix issue when a doc is added (#231)

* Simplify function, return error if doc not found
This commit is contained in:
Héctor Ramos 2017-11-15 15:55:08 -08:00 committed by Joel Marcey
parent 420d2e86fb
commit 09726c6361

View file

@ -131,6 +131,11 @@ files.forEach(file => {
// returns the version to use for a document based on its id and
// 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.`
);
}
// 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
let requestedFound = false;
@ -141,16 +146,11 @@ function docVersion(id, req_version) {
if (!requestedFound) {
continue;
}
if (!available[id]) {
return null;
}
if (available[id].has(versions[i])) {
return versions[i];
}
}
throw new Error(
`No document with id '${id}' available for use in version ${req_version} of the website. Verify that all version files are correct. Was the document deleted in a past version?`
);
return null;
}
// returns whether a given file has content that differ from the