jenkins-bot has submitted this change and it was merged.

Change subject: Regularize getToolSet return values
......................................................................


Regularize getToolSet return values

Change-Id: I08077f346213c5a3e6ba017947567f4061a36d5f
---
M ContentTranslationService.js
M registry/index.js
2 files changed, 6 insertions(+), 12 deletions(-)

Approvals:
  Amire80: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/ContentTranslationService.js b/ContentTranslationService.js
index 057446a..6e7a5eb 100644
--- a/ContentTranslationService.js
+++ b/ContentTranslationService.js
@@ -98,7 +98,7 @@
                toolset;
 
        toolset = registry.getToolSet( sourceLang, targetLang );
-       if ( !toolset || !toolset.mt ) {
+       if ( !toolset.mt ) {
                res.send( 404 );
                return;
        }
@@ -141,7 +141,7 @@
                toolset;
 
        toolset = registry.getToolSet( from, to );
-       if ( !toolset || !toolset.dictionary ) {
+       if ( !toolset.dictionary ) {
                res.send( 404 );
                return;
        }
@@ -160,18 +160,12 @@
 } );
 
 app.get( '/list/:tool/:from/:to', function ( req, res ) {
-       var result = {},
-               tool = req.params.tool,
+       var tool = req.params.tool,
                from = req.params.from,
                to = req.params.to,
                registry = require( __dirname + '/registry' ),
                toolset = registry.getToolSet( from, to );
-
-       if ( toolset ) {
-               result = toolset[ tool ];
-       }
-
-       res.json( result );
+       res.json( toolset[ tool ] || {} );
 } );
 
 app.get( '/version', function ( req, res ) {
diff --git a/registry/index.js b/registry/index.js
index 841fc52..eb5b1df 100644
--- a/registry/index.js
+++ b/registry/index.js
@@ -4,9 +4,9 @@
  * Get the available toolset for the given language pair
  * @param {string} from source language
  * @param {string} to target language
- * @return {Object} the toolset
+ * @return {Object} the toolset (empty object if nothing available)
  */
 function getToolSet( from, to ) {
-       return registry[ from ][ to ];
+       return ( registry[ from ] || {} )[ to ] || {};
 }
 module.exports.getToolSet = getToolSet;

-- 
To view, visit https://gerrit.wikimedia.org/r/147072
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I08077f346213c5a3e6ba017947567f4061a36d5f
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/services/cxserver
Gerrit-Branch: master
Gerrit-Owner: Divec <[email protected]>
Gerrit-Reviewer: Amire80 <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to