Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
75.00% |
3 / 4 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
FailStatusUtilTrait | |
75.00% |
3 / 4 |
|
0.00% |
0 / 1 |
2.06 | |
0.00% |
0 / 1 |
exitWithStatus | |
75.00% |
3 / 4 |
|
0.00% |
0 / 1 |
2.06 |
1 | <?php |
2 | |
3 | declare( strict_types=1 ); |
4 | |
5 | namespace MediaWiki\Extension\CampaignEvents\Rest; |
6 | |
7 | use InvalidArgumentException; |
8 | use MediaWiki\Rest\LocalizedHttpException; |
9 | use StatusValue; |
10 | use Wikimedia\Message\MessageValue; |
11 | |
12 | /** |
13 | * Helper to exit in case of a fatal StatusValue. |
14 | */ |
15 | trait FailStatusUtilTrait { |
16 | /** |
17 | * @param StatusValue $status |
18 | * @param int $statusCode |
19 | * @return never |
20 | */ |
21 | private function exitWithStatus( StatusValue $status, int $statusCode = 400 ): void { |
22 | $msgs = $status->getMessages(); |
23 | if ( !$msgs ) { |
24 | throw new InvalidArgumentException( "Got status without errors" ); |
25 | } |
26 | // TODO Report all errors, not just the first one. |
27 | throw new LocalizedHttpException( MessageValue::newFromSpecifier( $msgs[0] ), $statusCode ); |
28 | } |
29 | } |