Add friendlier message for short userID

This commit is contained in:
Ajay Ramachandran
2021-07-16 16:19:00 -04:00
parent ce2aa67832
commit 3f6baebd71

View File

@@ -338,11 +338,13 @@ export async function postSkipSegments(req: Request, res: Response): Promise<Res
}); });
const invalidFields = []; const invalidFields = [];
const errors = [];
if (typeof videoID !== 'string') { if (typeof videoID !== 'string') {
invalidFields.push('videoID'); invalidFields.push('videoID');
} }
if (typeof userID !== 'string' || userID.length < 30) { if (typeof userID !== 'string' || userID.length < 30) {
invalidFields.push('userID'); invalidFields.push('userID');
if (userID.length < 30) errors.push(`userID must be at least 30 characters long`);
} }
if (!Array.isArray(segments) || segments.length < 1) { if (!Array.isArray(segments) || segments.length < 1) {
invalidFields.push('segments'); invalidFields.push('segments');
@@ -350,8 +352,9 @@ export async function postSkipSegments(req: Request, res: Response): Promise<Res
if (invalidFields.length !== 0) { if (invalidFields.length !== 0) {
// invalid request // invalid request
const fields = invalidFields.reduce((p, c, i) => p + (i !== 0 ? ', ' : '') + c, ''); const formattedFields = invalidFields.reduce((p, c, i) => p + (i !== 0 ? ', ' : '') + c, '');
return res.status(400).send(`No valid ${fields} field(s) provided`); const formattedErrors = errors.reduce((p, c, i) => p + (i !== 0 ? '. ' : ' ') + c, '');
return res.status(400).send(`No valid ${formattedFields} field(s) provided.${formattedErrors}`);
} }
//hash the userID //hash the userID