Automattic\WooCommerce\StoreApi\Routes\V1

AbstractCartRoute::get_route_error_response()protectedWC 1.0

Get route response when something went wrong.

Method of the class: AbstractCartRoute{}

No Hooks.

Return

\WP_Error. WP Error object.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_route_error_response( $error_code, $error_message, $http_status_code, $additional_data );
$error_code(string) (required)
String based error code.
$error_message(string) (required)
User facing error message.
$http_status_code(int)
HTTP status.
Default: 500
$additional_data(array)
Extra data (key value pairs) to expose in the error response.
Default: []

AbstractCartRoute::get_route_error_response() code WC 9.4.2

protected function get_route_error_response( $error_code, $error_message, $http_status_code = 500, $additional_data = [] ) {
	$additional_data['status'] = $http_status_code;

	// If there was a conflict, return the cart so the client can resolve it.
	if ( 409 === $http_status_code ) {
		$additional_data['cart'] = $this->cart_schema->get_item_response( $this->cart_controller->get_cart_for_response() );
	}

	return new \WP_Error( $error_code, $error_message, $additional_data );
}