mirror of
https://github.com/wassname/talk.git
synced 2026-09-30 11:43:46 +08:00
Handle timeout and failure of perspective api
This commit is contained in:
1 parent
f1c5d479ad
commit
f82a0c80bf
3 files changed
+50
-10
No files matched your search
@@ -12,8 +12,19 @@ module.exports = {
|
||||
createComment: {
|
||||
async pre(_, {input}, _context, _info) {
|
||||
|
||||
// TODO: handle timeouts.
|
||||
const scores = await getScores(input.body);
|
||||
let scores;
|
||||
|
||||
// Try getting scores.
|
||||
try {
|
||||
scores = await getScores(input.body);
|
||||
}
|
||||
catch(err) {
|
||||
|
||||
// Warn and let mutation pass.
|
||||
console.trace(err);
|
||||
return;
|
||||
}
|
||||
|
||||
const commentIsToxic = isToxic(scores);
|
||||
|
||||
if (input.checkToxicity && commentIsToxic) {
|
||||
@@ -32,7 +43,8 @@ module.exports = {
|
||||
}
|
||||
},
|
||||
async post(_, _input, _context, _info, result) {
|
||||
if (isToxic(result.comment.metadata.perspective)) {
|
||||
const metadata = result.comment.metadata;
|
||||
if (metadata.perspective && isToxic(metadata.perspective)) {
|
||||
|
||||
// TODO: this is kind of fragile, we should refactor this to resolve
|
||||
// all these const's that we're using like 'COMMENTS', 'FLAG' to be
|
||||
|
||||
Reference in new issue
Block a user