ApiErrorReporter is a component for API modules that handles error reporting.
More...
|
| __construct (ApiBase $apiModule, ExceptionLocalizer $localizer) |
|
| reportStatusWarnings (StatusValue $status) |
| Reports any warnings in the StatusValue object on the warnings section of the result.
|
|
| dieStatus (StatusValue $status, $errorCode) |
| Aborts the request with an error based on the given (fatal) StatusValue.
|
|
| dieException (Exception $ex, $errorCode, $httpRespCode=0, $extraData=[]) |
| Aborts the request with an error based on the given Exception.
|
|
| dieWithError ( $msg, $errorCode, $httpRespCode=0, $extraData=[]) |
|
| dieError ( $description, $errorCode, $httpRespCode=0, $extraData=[]) |
| Aborts the request with an error code.
|
|
| addStatusToResult (StatusValue $status, &$data) |
| Add the messages from the given StatusValue object to the $data array, for use in an error report.
|
|
ApiErrorReporter is a component for API modules that handles error reporting.
It supports localization of error messages.
- Copyright
- GPL-2.0-or-later
- Author
- Daniel Kinzler
◆ __construct()
Wikibase\Repo\Api\ApiErrorReporter::__construct |
( |
ApiBase | $apiModule, |
|
|
ExceptionLocalizer | $localizer ) |
- Parameters
-
ApiBase | $apiModule | the API module for collaboration |
ExceptionLocalizer | $localizer | |
◆ addMessageToResult()
Wikibase\Repo\Api\ApiErrorReporter::addMessageToResult |
( |
MessageSpecifier | $message, |
|
|
& | $data ) |
|
private |
Add the given message to the $data array, for use in an error report.
- Parameters
-
MessageSpecifier | $message | |
array | null | &$data | |
- Exceptions
-
◆ addStatusToResult()
Wikibase\Repo\Api\ApiErrorReporter::addStatusToResult |
( |
StatusValue | $status, |
|
|
& | $data ) |
Add the messages from the given StatusValue object to the $data array, for use in an error report.
- Parameters
-
StatusValue | $status | |
array | null | &$data | |
- Exceptions
-
◆ convertMessageToResult()
Wikibase\Repo\Api\ApiErrorReporter::convertMessageToResult |
( |
MessageSpecifier | $message | ) |
|
|
private |
Constructs a result structure from the given message.
- Parameters
-
- Returns
- array
◆ convertWarningsToResult()
Wikibase\Repo\Api\ApiErrorReporter::convertWarningsToResult |
( |
array | $messageSpecs | ) |
|
|
private |
Utility method for compiling a list of warning messages into a form suitable for use in an API result structure.
- Parameters
-
MessageSpecifier[] | $messageSpecs | Warnings returned by StatusValue::getMessages() |
- Returns
- array A result structure containing the messages
◆ dieError()
Wikibase\Repo\Api\ApiErrorReporter::dieError |
( |
| $description, |
|
|
| $errorCode, |
|
|
| $httpRespCode = 0, |
|
|
| $extraData = [] ) |
Aborts the request with an error code.
This is intended as a drop-in replacement for ApiBase::dieWithError().
Localization of the error code is attempted by looking up a message key constructed using the given code in "wikibase-api-$errorCode". If such a message exists, it is included in the error's extra data.
- See also
- ApiBase::dieWithError()
- Deprecated
- Use dieWithError() instead.
- Parameters
-
string | $description | An english, plain text description of the error, for use in logs. |
string | $errorCode | A code identifying the error |
int | $httpRespCode | The HTTP error code to send to the client |
array | null | $extraData | Any extra data to include in the error report |
- Returns
- never
- Exceptions
-
ApiUsageException | always |
LogicException | |
◆ dieException()
Wikibase\Repo\Api\ApiErrorReporter::dieException |
( |
Exception | $ex, |
|
|
| $errorCode, |
|
|
| $httpRespCode = 0, |
|
|
| $extraData = [] ) |
Aborts the request with an error based on the given Exception.
This is intended as an alternative for ApiBase::dieWithError().
If possible, a localized error message based on the exception is included in the error sent to the client. Localization of errors is attempted using the ExceptionLocalizer service provided to the constructor. If that fails, dieWithError() is called, which in turn attempts localization based on the error code.
- See also
- ApiBase::dieWithError()
- Parameters
-
Exception | $ex | The exception to report. $ex->getMessage() will be used as the error's free form description. |
string | $errorCode | A code identifying the error. |
int | $httpRespCode | The HTTP error code to send to the client |
array | null | $extraData | Any extra data to include in the error report |
- Returns
- never
- Exceptions
-
ApiUsageException | |
LogicException | |
◆ dieStatus()
Wikibase\Repo\Api\ApiErrorReporter::dieStatus |
( |
StatusValue | $status, |
|
|
| $errorCode ) |
Aborts the request with an error based on the given (fatal) StatusValue.
This is intended as an alternative for ApiBase::dieWithError().
If possible, a localized error message based on the exception is included in the error sent to the client. Localization of errors is attempted using the ExceptionLocalizer service provided to the constructor. If that fails, dieWithError() is called, which in turn attempts localization based on the error code.
- See also
- ApiBase::dieWithError()
- Parameters
-
StatusValue | $status | The status to report. $status->getMessage() will be used to generate the error's free form description. |
string | $errorCode | A code identifying the error. |
- Returns
- never
- Exceptions
-
ApiUsageException | |
LogicException | |
◆ dieWithError()
Wikibase\Repo\Api\ApiErrorReporter::dieWithError |
( |
| $msg, |
|
|
| $errorCode, |
|
|
| $httpRespCode = 0, |
|
|
| $extraData = [] ) |
- See also
- ApiBase::dieWithError
- Parameters
-
string | string[] | MessageSpecifier | $msg | |
string | $errorCode | A code identifying the error. |
int | $httpRespCode | The HTTP error code to send to the client |
array | null | $extraData | Any extra data to include in the error report |
- Returns
- never
- Exceptions
-
ApiUsageException | always |
LogicException | |
◆ getMessageForCode()
Wikibase\Repo\Api\ApiErrorReporter::getMessageForCode |
( |
| $errorCode, |
|
|
| $description, |
|
|
array | $extraData = null ) |
|
private |
- Parameters
-
string | $errorCode | A code identifying the error. |
string | null | $description | Plain text english message |
array | null | $extraData | Any extra data to include in the error report |
- Returns
- ApiMessage
◆ getPlainErrorMessageFromStatus()
Wikibase\Repo\Api\ApiErrorReporter::getPlainErrorMessageFromStatus |
( |
StatusValue | $status | ) |
|
|
private |
- Parameters
-
- Returns
- string|null a plain text english error message, or null
◆ reportStatusWarnings()
Wikibase\Repo\Api\ApiErrorReporter::reportStatusWarnings |
( |
StatusValue | $status | ) |
|
Reports any warnings in the StatusValue object on the warnings section of the result.
- Parameters
-
◆ setWarning()
Wikibase\Repo\Api\ApiErrorReporter::setWarning |
( |
| $key, |
|
|
| $warningData ) |
|
private |
Set warning section for this module.
- Note
- Only needed when ApiErrorFormatter_BackCompat is in use.
- Parameters
-
string | $key | |
string | array | $warningData | Warning message |
◆ $apiModule
Wikibase\Repo\Api\ApiErrorReporter::$apiModule |
|
private |
◆ $localizer
Wikibase\Repo\Api\ApiErrorReporter::$localizer |
|
private |
The documentation for this class was generated from the following file: