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

Change subject: Improve mt error handling and reporting
......................................................................


Improve mt error handling and reporting

Moved public/mt to public/translation to avoid
collition with mt API URL

Change-Id: I5c3450a06ac24216611336429c154804a1110009
---
M ContentTranslationService.js
R public/translation/css/main.css
R public/translation/index.html
R public/translation/js/main.js
4 files changed, 14 insertions(+), 6 deletions(-)

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



diff --git a/ContentTranslationService.js b/ContentTranslationService.js
index 2719eb1..142a1de 100644
--- a/ContentTranslationService.js
+++ b/ContentTranslationService.js
@@ -91,6 +91,10 @@
        );
 } );
 
+app.get( '/mt/:from/:to/:provider?', function ( req, res ) {
+       res.send( 405, { error: 'Request must be posted' } );
+} );
+
 app.post( '/mt/:from/:to/:provider?', function ( req, res ) {
        var mtClients, mtClient,
                sourceHtmlChunks, sourceHtml, reqLength,
@@ -100,13 +104,19 @@
                provider = registry.getValidProvider( from, to, 'mt', 
req.params.provider );
 
        if ( !provider ) {
-               res.send( 404 );
+               res.send( 404, { error: 'Provider not supported' } );
                logger.info( 'MT provider invalid or missing' );
 
                return;
        }
 
        mtClients = require( __dirname + '/mt/' );
+       if ( mtClients[provider] === undefined ) {
+               res.send( 500, { error: 'Provider not found' } );
+               logger.error( 'Configured provider ' + provider + ' was not 
found' );
+               return;
+       }
+
        mtClient = mtClients[ provider ];
 
        sourceHtmlChunks = [ '<div>' ];
@@ -116,7 +126,7 @@
                reqLength += data.length;
                if ( reqLength > 50000 ) {
                        // Too long
-                       res.send( 500 );
+                       res.send( 413, { error: 'Content too long' } );
                        logger.error( 'MT content too long' );
                        return;
                }
@@ -126,16 +136,14 @@
                sourceHtmlChunks.push( '</div>' );
                sourceHtml = sourceHtmlChunks.join( '' );
 
-               logger.profile( 'MT');
+               logger.profile( 'MT' );
                mtClient.translate( from, to, sourceHtml ).then(
                        function ( data ) {
                                res.send( data );
                                logger.profile( 'MT', { from: from, to: to } );
                        },
                        function ( error ) {
-                               res.send( 500, {
-                                       error: error
-                               } );
+                               res.send( 500, { error: error } );
                                logger.log( 'error', 'MT processing error: 
(%s)', error.toString() );
                        }
                );
diff --git a/public/mt/css/main.css b/public/translation/css/main.css
similarity index 100%
rename from public/mt/css/main.css
rename to public/translation/css/main.css
diff --git a/public/mt/index.html b/public/translation/index.html
similarity index 100%
rename from public/mt/index.html
rename to public/translation/index.html
diff --git a/public/mt/js/main.js b/public/translation/js/main.js
similarity index 100%
rename from public/mt/js/main.js
rename to public/translation/js/main.js

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I5c3450a06ac24216611336429c154804a1110009
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/services/cxserver
Gerrit-Branch: master
Gerrit-Owner: Nikerabbit <[email protected]>
Gerrit-Reviewer: Nikerabbit <[email protected]>
Gerrit-Reviewer: Santhosh <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to