-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Update file permission function to validate request body
- Loading branch information
Showing
2 changed files
with
30 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* Throws an error if any of the keys are missing from the object | ||
* @param {*} obj | ||
* @param {string[]} keys | ||
* @throws {Error} | ||
*/ | ||
export function throwIfMissing(obj, keys) { | ||
const missing = []; | ||
for (let key of keys) { | ||
if (!(key in obj) || !obj[key]) { | ||
missing.push(key); | ||
} | ||
} | ||
if (missing.length > 0) { | ||
throw new Error(`Missing required fields: ${missing.join(', ')}`); | ||
} | ||
} |