Physikerwelt has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/305310

Change subject: Improve error reporting
......................................................................

Improve error reporting

Display error message in the UI,
if the check command passes,
but the mml/svg/complete endpoints returns an valid json error.

Bug: T143225
Change-Id: I50776926e42f75a2c1e30fc9afe08baae3fcdbd1
---
M MathRestbaseInterface.php
M tests/MathRestBaseInterfaceTest.php
2 files changed, 33 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Math 
refs/changes/10/305310/1

diff --git a/MathRestbaseInterface.php b/MathRestbaseInterface.php
index f223b0a..6099a41 100644
--- a/MathRestbaseInterface.php
+++ b/MathRestbaseInterface.php
@@ -428,6 +428,20 @@
                        'math_type' => $type,
                        'tex' => $this->tex
                ] );
-               throw new MWException( "Cannot get $type. Server problem." );
+               self::throwContentError( $type, $response['body'] );
+       }
+
+       /**
+        * @param $type
+        * @param $body
+        * @throws MWException
+        */
+       public static function throwContentError( $type, $body ) {
+               $detail = 'Server problem.';
+               $json = json_decode( $body );
+               if ( isset( $json->detail ) && is_array( $json->detail ) ) {
+                       $detail = $json->detail[0];
+               }
+               throw new MWException( "Cannot get $type. $detail" );
        }
 }
diff --git a/tests/MathRestBaseInterfaceTest.php 
b/tests/MathRestBaseInterfaceTest.php
index af21836..e5377f6 100644
--- a/tests/MathRestBaseInterfaceTest.php
+++ b/tests/MathRestBaseInterfaceTest.php
@@ -85,4 +85,22 @@
                $rbi->getFullSvgUrl();
        }
 
+       /**
+        * Incorporate the "details" in the error message, if the check 
requests passes, but the
+        * mml/svg/complete endpoints returns an error
+        * @expectedException MWException
+        * @expectedExceptionMessage Cannot get mml. TeX parse error: Missing 
close brace
+        */
+       public function testLateError() {
+               $input = 
'{"type":"https://mediawiki.org/wiki/HyperSwitch/errors/bad_request","title":"Bad
 Request","method":"POST","detail":["TeX parse error: Missing close 
brace"],"uri":"/complete"}';
+               MathRestbaseInterface::throwContentError( 'mml', $input );
+       }
+       /**
+        * @expectedException MWException
+        * @expectedExceptionMessage Cannot get mml. Server problem.
+        */
+       public function testLateErrorNoDetail() {
+               $input = '';
+               MathRestbaseInterface::throwContentError( 'mml', $input );
+       }
 }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I50776926e42f75a2c1e30fc9afe08baae3fcdbd1
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Math
Gerrit-Branch: master
Gerrit-Owner: Physikerwelt <[email protected]>

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

Reply via email to