Automattic\WooCommerce\StoreApi\Routes\V1
Checkout::get_route_error_response()
Get route response when something went wrong.
Метод класса: Checkout{}
Хуков нет.
Возвращает
\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.
По умолчанию: []
Код Checkout::get_route_error_response() Checkout::get route error response WC 7.5.1
protected function get_route_error_response( $error_code, $error_message, $http_status_code = 500, $additional_data = [] ) { $error_from_message = new \WP_Error( $error_code, $error_message ); // 409 is when there was a conflict, so we return the cart so the client can resolve it. if ( 409 === $http_status_code ) { return $this->add_data_to_error_object( $error_from_message, $additional_data, $http_status_code, true ); } return $this->add_data_to_error_object( $error_from_message, $additional_data, $http_status_code ); }