mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-14 23:47:00 +03:00
improved error handling
This commit is contained in:
@@ -16,7 +16,10 @@ module.exports = (req, res) => {
|
|||||||
|| !Array.isArray(categorys)
|
|| !Array.isArray(categorys)
|
||||||
|| categorys.length === 0
|
|| categorys.length === 0
|
||||||
) {
|
) {
|
||||||
res.status(400).json({});
|
res.status(400).json({
|
||||||
|
status: 400,
|
||||||
|
message: 'Bad Format'
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,7 +28,10 @@ module.exports = (req, res) => {
|
|||||||
let userIsVIP = isUserVIP(userID);
|
let userIsVIP = isUserVIP(userID);
|
||||||
|
|
||||||
if (!userIsVIP) {
|
if (!userIsVIP) {
|
||||||
res.status(403).json({});
|
res.status(403).json({
|
||||||
|
status: 403,
|
||||||
|
message: 'Must be a VIP to mark videos.'
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,8 +45,10 @@ module.exports = (req, res) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// get user categorys not already submitted
|
// get user categorys not already submitted that match accepted format
|
||||||
let categorysToMark = categorys.filter((category) => {
|
let categorysToMark = categorys.filter((category) => {
|
||||||
|
return !!category.match(/^[a-zA-Z]+$/);
|
||||||
|
}).filter((category) => {
|
||||||
return noSegmentList.indexOf(category) === -1;
|
return noSegmentList.indexOf(category) === -1;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -51,8 +59,16 @@ module.exports = (req, res) => {
|
|||||||
|
|
||||||
// create database entry
|
// create database entry
|
||||||
categorysToMark.forEach((category) => {
|
categorysToMark.forEach((category) => {
|
||||||
db.prepare('run', "INSERT INTO noSegments (videoID, userID, category) VALUES(?, ?, ?)", [videoID, userID, category]);
|
try {
|
||||||
//ogger.debug('submitting ' + category);
|
db.prepare('run', "INSERT INTO noSegments (videoID, userID, category) VALUES(?, ?, ?)", [videoID, userID, category]);
|
||||||
|
} catch (err) {
|
||||||
|
logger.error("Error submitting 'noSegment' marker for category '" + category + "' for video '" + videoID + "'");
|
||||||
|
logger.error(err);
|
||||||
|
res.status(500).json({
|
||||||
|
status: 500,
|
||||||
|
message: "Internal Server Error: Could not write marker to the database."
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
|
|||||||
@@ -31,6 +31,8 @@ describe('postNoSegments', () => {
|
|||||||
'outro',
|
'outro',
|
||||||
'shilling',
|
'shilling',
|
||||||
'shilling',
|
'shilling',
|
||||||
|
'shil ling',
|
||||||
|
'',
|
||||||
'intro'
|
'intro'
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
@@ -68,6 +70,8 @@ describe('postNoSegments', () => {
|
|||||||
'outro',
|
'outro',
|
||||||
'shilling',
|
'shilling',
|
||||||
'shilling',
|
'shilling',
|
||||||
|
'shil ling',
|
||||||
|
'',
|
||||||
'intro'
|
'intro'
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user