From cff9b29a360f6db4ccf9ed548db2a97732bf450c Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Mon, 22 Oct 2018 12:22:01 -0600 Subject: [PATCH] fix: adjust perspective defaults when failure occurs --- .../server/perspective.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/plugins/talk-plugin-toxic-comments/server/perspective.js b/plugins/talk-plugin-toxic-comments/server/perspective.js index 424543b2b..7966d3b36 100644 --- a/plugins/talk-plugin-toxic-comments/server/perspective.js +++ b/plugins/talk-plugin-toxic-comments/server/perspective.js @@ -10,7 +10,8 @@ const debug = require('debug')('talk:plugin:toxic-comments'); /** * Get scores from the perspective api - * @param {string} text text to be anaylized + * + * @param {string} text text to be analyzed * @return {object} object containing toxicity scores */ async function getScores(text) { @@ -43,13 +44,13 @@ async function getScores(text) { // If we get an error, just say it's not a toxic comment. if (data.error) { - debug('Recieved Error when submitting: %o', data.error); + debug('Received Error when submitting: %o', data.error); return { TOXICITY: { - summaryScore: 0.0, + summaryScore: null, }, SEVERE_TOXICITY: { - summaryScore: 0.0, + summaryScore: null, }, }; } @@ -66,6 +67,7 @@ async function getScores(text) { /** * Get toxicity probability + * * @param {object} scores scores as returned by `getScores` * @return {number} toxicity probability from 0 - 1.0 */ @@ -74,7 +76,9 @@ function getProbability(scores) { } /** - * isToxic determines if given probabilty or scores meets the toxicity threshold. + * isToxic determines if given probability or scores meets the toxicity + * threshold. + * * @param {object|number} scoresOrProbability scores or probability * @return {boolean} */ @@ -89,6 +93,7 @@ function isToxic(scoresOrProbability) { /** * maskKeyInError is a decorator that calls fn and masks the * API_KEY in errors before throwing. + * * @param {function} fn Function that returns a Promise * @return {function} decorated function */