Merge pull request #251 from mchangrh/getSkipSegment-400

skipSegments return 400 if bad categories
This commit is contained in:
Ajay Ramachandran 2021-06-16 00:46:54 -04:00 committed by GitHub
commit 47ddaaad7b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View file

@ -306,7 +306,9 @@ async function endpoint(req: Request, res: Response): Promise<void> {
res.send(segments);
}
} catch (err) {
res.status(500).send();
if (err instanceof SyntaxError) {
res.status(400).send("Categories parameter does not match format requirements.");
} else res.status(500).send();
}
}

View file

@ -227,6 +227,14 @@ describe('getSkipSegments', () => {
.catch(err => ("couldn't call endpoint"));
});
it('Should return 400 if bad categories argument', (done: Done) => {
fetch(getbaseURL() + "/api/skipSegments?videoID=testtesttest&categories=[not-quoted,not-quoted]")
.then(res => {
if (res.status !== 400) done("non 400 respone code: " + res.status);
else done(); // pass
})
.catch(err => ("couldn't call endpoint"));
});
it('Should be able send a comma in a query param', () => {
fetch(getbaseURL() + "/api/skipSegments?videoID=testtesttest,test&category=sponsor")