Automattic\WooCommerce\StoreApi\Routes\V1

AbstractCartRoute::get_route_error_response()protectedWC 1.0

Get route response when something went wrong.

Метод класса: AbstractCartRoute{}

Хуков нет.

Возвращает

\WP_Error. WP Error object.

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->get_route_error_response( $error_code, $error_message, $http_status_code, $additional_data );
$error_code(строка) (обязательный)
String based error code.
$error_message(строка) (обязательный)
User facing error message.
$http_status_code(int)
HTTP status.
По умолчанию: 500
$additional_data(массив)
Extra data (key value pairs) to expose in the error response.
По умолчанию: []

Код AbstractCartRoute::get_route_error_response() WC 8.7.0

protected function get_route_error_response( $error_code, $error_message, $http_status_code = 500, $additional_data = [] ) {
	switch ( $http_status_code ) {
		case 409:
			// If there was a conflict, return the cart so the client can resolve it.
			$cart = $this->cart_controller->get_cart_instance();

			return new \WP_Error(
				$error_code,
				$error_message,
				array_merge(
					$additional_data,
					[
						'status' => $http_status_code,
						'cart'   => $this->cart_schema->get_item_response( $cart ),
					]
				)
			);
	}

	return new \WP_Error( $error_code, $error_message, [ 'status' => $http_status_code ] );
}