Use join function for simplicity

This commit is contained in:
HanYaodong 2024-06-13 10:35:23 +08:00
parent 738f863581
commit 374ddc74bd
2 changed files with 4 additions and 4 deletions

View file

@ -23,7 +23,7 @@ export async function postClearCache(req: Request, res: Response): Promise<Respo
if (invalidFields.length !== 0) {
// invalid request
const fields = invalidFields.reduce((p, c, i) => p + (i !== 0 ? ", " : "") + c, "");
const fields = invalidFields.join(", ");
return res.status(400).send(`No valid ${fields} field(s) provided`);
}

View file

@ -242,11 +242,11 @@ async function checkInvalidFields(videoID: VideoID, userID: UserID, hashedUserID
if (invalidFields.length !== 0) {
// invalid request
const formattedFields = invalidFields.reduce((p, c, i) => p + (i !== 0 ? ", " : "") + c, "");
const formattedErrors = errors.reduce((p, c, i) => p + (i !== 0 ? ". " : " ") + c, "");
const formattedFields = invalidFields.join(", ");
const formattedErrors = errors.join(". ");
return {
pass: false,
errorMessage: `No valid ${formattedFields}.${formattedErrors}`,
errorMessage: `No valid ${formattedFields}. ${formattedErrors}`,
errorCode: 400
};
}