Automattic\WooCommerce\RestApi\Routes\V4
AbstractController::get_route_error_response
Get route response when something went wrong.
Метод класса: AbstractController{}
Хуков нет.
Возвращает
WP_Error. WP Error object.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->get_route_error_response( $error_code, $error_message, $http_status_code, $additional_data ): WP_Error;
- $error_code(строка) (обязательный)
- String based error code.
- $error_message(строка) (обязательный)
- User facing error message.
- $http_status_code(int)
- HTTP status.
По умолчанию: 400 - $additional_data(массив)
- Extra data (key value pairs) to expose in the error response.
По умолчанию: array()
Список изменений
| С версии 10.2.0 | Введена. |
Код AbstractController::get_route_error_response() AbstractController::get route error response WC 10.3.6
protected function get_route_error_response( string $error_code, string $error_message, int $http_status_code = WP_Http::BAD_REQUEST, array $additional_data = array() ): WP_Error {
if ( empty( $error_code ) ) {
$error_code = 'invalid_request';
}
if ( empty( $error_message ) ) {
$error_message = __( 'An error occurred while processing your request.', 'woocommerce' );
}
return new WP_Error(
$error_code,
$error_message,
array_merge(
$additional_data,
array( 'status' => $http_status_code )
)
);
}