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
This commit is contained in:
parent
13b9857115
commit
f5fdda0ba1
|
@ -428,6 +428,24 @@ class MathRestbaseInterface {
|
||||||
'math_type' => $type,
|
'math_type' => $type,
|
||||||
'tex' => $this->tex
|
'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 ) ) {
|
||||||
|
if ( is_array( $json->detail ) ){
|
||||||
|
$detail = $json->detail[0];
|
||||||
|
} elseif ( is_string( $json->detail ) ) {
|
||||||
|
$detail = $json->detail;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new MWException( "Cannot get $type. $detail" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,4 +85,38 @@ class MathRestbaseInterfaceTest extends MediaWikiTestCase {
|
||||||
$rbi->getFullSvgUrl();
|
$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() {
|
||||||
|
// @codingStandardsIgnoreStart
|
||||||
|
$input = '{"type":"https://mediawiki.org/wiki/HyperSwitch/errors/bad_request","title":"Bad Request","method":"POST","detail":["TeX parse error: Missing close brace"],"uri":"/complete"}';
|
||||||
|
// @codingStandardsIgnoreEnd
|
||||||
|
MathRestbaseInterface::throwContentError( 'mml', $input );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 testLateErrorString() {
|
||||||
|
// @codingStandardsIgnoreStart
|
||||||
|
$input = '{"type":"https://mediawiki.org/wiki/HyperSwitch/errors/bad_request","title":"Bad Request","method":"POST","detail": "TeX parse error: Missing close brace","uri":"/complete"}';
|
||||||
|
// @codingStandardsIgnoreEnd
|
||||||
|
MathRestbaseInterface::throwContentError( 'mml', $input );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException MWException
|
||||||
|
* @expectedExceptionMessage Cannot get mml. Server problem.
|
||||||
|
*/
|
||||||
|
public function testLateErrorNoDetail() {
|
||||||
|
$input = '';
|
||||||
|
MathRestbaseInterface::throwContentError( 'mml', $input );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue