Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 5 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
ErrorException | |
0.00% |
0 / 5 |
|
0.00% |
0 / 4 |
20 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
getStatus | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getErrorMessage | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getErrorMessageInEnglish | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace GrowthExperiments; |
4 | |
5 | use Exception; |
6 | use MediaWiki\Status\Status; |
7 | use StatusValue; |
8 | |
9 | /** |
10 | * Generic exception class for things that are too rare or unimportant to merit a custom |
11 | * exception class. |
12 | * The exception can wrap localized messages. It isn't feasible to have an exception with a |
13 | * localized message (since getMessage is final and localization has too many dependencies to |
14 | * be doable at exception construction time), so the assumption is that callers always catch |
15 | * this exception and render it appropriately. |
16 | */ |
17 | class ErrorException extends Exception { |
18 | |
19 | private StatusValue $status; |
20 | |
21 | /** |
22 | * @param StatusValue $error |
23 | */ |
24 | public function __construct( StatusValue $error ) { |
25 | parent::__construct( $error->__toString() ); |
26 | $this->status = $error; |
27 | } |
28 | |
29 | /** |
30 | * Get the raw error status. |
31 | * @return StatusValue |
32 | */ |
33 | public function getStatus(): StatusValue { |
34 | return $this->status; |
35 | } |
36 | |
37 | /** |
38 | * Get the error status as a localized string (intended for displaying errors to the user). |
39 | * @return string |
40 | */ |
41 | public function getErrorMessage(): string { |
42 | return Status::wrap( $this->status )->getWikiText(); |
43 | } |
44 | |
45 | /** |
46 | * Get the error status as an English string (intended for logging). |
47 | * @return string |
48 | */ |
49 | public function getErrorMessageInEnglish(): string { |
50 | return Status::wrap( $this->status )->getWikiText( false, false, 'en' ); |
51 | } |
52 | |
53 | } |