jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/394975 )

Change subject: Throw error if content to translate is not provided or empty
......................................................................


Throw error if content to translate is not provided or empty

This was hiding the error for the issue T173801

Bug: T173801
Change-Id: I2a75d4f04469d4c32e2b2dbdc5e5c9cbb41aace2
---
M lib/routes/v1.js
M lib/routes/v2.js
2 files changed, 9 insertions(+), 0 deletions(-)

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



diff --git a/lib/routes/v1.js b/lib/routes/v1.js
index 2652f4a..d34baf0 100644
--- a/lib/routes/v1.js
+++ b/lib/routes/v1.js
@@ -181,6 +181,10 @@
                // We support setting html as body or as body.html. But 
body.html is the recommended way.
                // The other way will be removed soon.
                sourceHtml = req.body.html || req.rawBody;
+               if ( !sourceHtml || sourceHtml.trim().length === 0 ) {
+                       res.status( 500 ).end( 'Content for machine translation 
is not given or is empty' );
+                       return;
+               }
                return mtClient.translate( from, to, sourceHtml ).then(
                        ( data ) => {
                                res.json( {
diff --git a/lib/routes/v2.js b/lib/routes/v2.js
index 00aa567..206845f 100644
--- a/lib/routes/v2.js
+++ b/lib/routes/v2.js
@@ -84,6 +84,11 @@
 
                sourceHtml = req.body.html;
 
+               if ( !sourceHtml || sourceHtml.trim().length === 0 ) {
+                       res.status( 500 ).end( 'Content for translate is not 
given or is empty' );
+                       return;
+               }
+
                if ( !mtClient ) {
                        machineTranslationRequest = Promise.resolve( sourceHtml 
);
                } else {

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

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

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

Reply via email to