Fix(routing): add protections against malformed data

This commit is contained in:
Berkeley Martinez
2016-08-05 14:49:23 -07:00
parent 91a50b4843
commit 3d05eee0ea
4 changed files with 84 additions and 55 deletions

View File

@@ -0,0 +1,13 @@
const emptyProtector = {
blocks: [],
challenges: []
};
// protect against malformed map data
// protect(block: { challenges: [], block: [] }|Void) => block|emptyProtector
export default function protect(block) {
// if no block or block has no challenges or blocks
if (!block || !(block.challenges || block.blocks)) {
return emptyProtector;
}
return block;
}