Wikibase
MediaWiki Wikibase extension
Loading...
Searching...
No Matches
Wikibase\Repo\Api\ApiErrorReporter Class Reference

ApiErrorReporter is a component for API modules that handles error reporting. More...

Public Member Functions

 __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.
 

Private Member Functions

 setWarning ( $key, $warningData)
 Set warning section for this module.
 
 getPlainErrorMessageFromStatus (StatusValue $status)
 
 getMessageForCode ( $errorCode, $description, array $extraData=null)
 
 addMessageToResult (MessageSpecifier $message, &$data)
 Add the given message to the $data array, for use in an error report.
 
 convertWarningsToResult (array $messageSpecs)
 Utility method for compiling a list of warning messages into a form suitable for use in an API result structure.
 
 convertMessageToResult (MessageSpecifier $message)
 Constructs a result structure from the given message.
 

Private Attributes

 $apiModule
 
 $localizer
 

Detailed Description

ApiErrorReporter is a component for API modules that handles error reporting.

It supports localization of error messages.

Author
Daniel Kinzler

Constructor & Destructor Documentation

◆ __construct()

Wikibase\Repo\Api\ApiErrorReporter::__construct ( ApiBase $apiModule,
ExceptionLocalizer $localizer )
Parameters
ApiBase$apiModulethe API module for collaboration
ExceptionLocalizer$localizer

Member Function Documentation

◆ 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
InvalidArgumentException

◆ 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
InvalidArgumentException

◆ convertMessageToResult()

Wikibase\Repo\Api\ApiErrorReporter::convertMessageToResult ( MessageSpecifier $message)
private

Constructs a result structure from the given message.

Parameters
MessageSpecifier$message
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[]$messageSpecsWarnings 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$descriptionAn english, plain text description of the error, for use in logs.
string$errorCodeA code identifying the error
int$httpRespCodeThe HTTP error code to send to the client
array | null$extraDataAny extra data to include in the error report
Returns
never
Exceptions
ApiUsageExceptionalways
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$exThe exception to report. $ex->getMessage() will be used as the error's free form description.
string$errorCodeA code identifying the error.
int$httpRespCodeThe HTTP error code to send to the client
array | null$extraDataAny 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$statusThe status to report. $status->getMessage() will be used to generate the error's free form description.
string$errorCodeA 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$errorCodeA code identifying the error.
int$httpRespCodeThe HTTP error code to send to the client
array | null$extraDataAny extra data to include in the error report
Returns
never
Exceptions
ApiUsageExceptionalways
LogicException

◆ getMessageForCode()

Wikibase\Repo\Api\ApiErrorReporter::getMessageForCode ( $errorCode,
$description,
array $extraData = null )
private
Parameters
string$errorCodeA code identifying the error.
string | null$descriptionPlain text english message
array | null$extraDataAny extra data to include in the error report
Returns
ApiMessage

◆ getPlainErrorMessageFromStatus()

Wikibase\Repo\Api\ApiErrorReporter::getPlainErrorMessageFromStatus ( StatusValue $status)
private
Parameters
StatusValue$status
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
StatusValue$status

◆ 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$warningDataWarning message

Member Data Documentation

◆ $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: