Skip to content

Commit 31a913d

Browse files
committed
bugfix + resilience in pointers
1 parent ad9646b commit 31a913d

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

‎src/routes/pointers/index.js‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ const escape = text => text && `"${text}"`;
3535
// Set forbidden reference value
3636
// These values will be excluded from the results when encountered
3737
const FORBIDDEN_REFERENCES = new Set([ undefined, 'noref', 'notfound' ]);
38+
// Set which reference have all-caps ids
39+
// Thus for these references, if the user asks for an id with no caps then we can fix it
40+
const ALL_CAPS_ID_REFERENCES = new Set([ 'proteins', 'inchikeys', 'pdbs', 'chains' ]);
3841

3942
// Set the response when a specific reference is requested
4043
// Return a list with all available reference ids
@@ -58,7 +61,10 @@ const pointersEndpoint = handler({
5861
error: `Not suppoted reference "${referenceName}". Available references: ${availableReferences}`
5962
}
6063
// Check if a specific reference id is requested
61-
const targetReferenceId = request.params.id;
64+
let targetReferenceId = request.params.id;
65+
// Make the reference ids upper when pertinent
66+
if (targetReferenceId && ALL_CAPS_ID_REFERENCES.has(referenceName))
67+
targetReferenceId = targetReferenceId.toUpperCase();
6268
const hasTarget = targetReferenceId !== undefined;
6369
// Set a getter function for the project reference ids field
6470
const idsField = reference.projectIdsField;
@@ -84,12 +90,7 @@ const pointersEndpoint = handler({
8490
// Consume the projects cursor
8591
const projectsData = await projectsCursor.toArray();
8692
// If no projects were found then it means some reference id was searched and not found
87-
if (projectsData.length === 0) return {
88-
headerError: NOT_FOUND,
89-
error: targetReferenceId
90-
? `No project was found to include references to "${targetReferenceId}" ${referenceName}`
91-
: `There are no references to ${referenceName} at all`
92-
}
93+
// However there may be external pointers with the requested reference id so we must keep going
9394
// Set projected field value getters for later
9495
const projectionValueGetters = Object.fromEntries(
9596
projection.map(field => [ field, getValueGetter(field) ])
@@ -297,6 +298,13 @@ const pointersEndpoint = handler({
297298
});
298299
});
299300
}
301+
// If no pointers were found after all then complain
302+
if (Object.keys(pointers).length === 0) return {
303+
headerError: NOT_FOUND,
304+
error: targetReferenceId
305+
? `No project or external pointer was found to include references to "${targetReferenceId}" ${referenceName}`
306+
: `There are no references to ${referenceName} at all`
307+
}
300308
// If there is no output format then return the response as is
301309
if (format === 'json') return hasTarget ? pointers[targetReferenceId] : pointers;
302310
// At this point (for now) it means the requested format is CSV

0 commit comments

Comments
 (0)