Automattic\WooCommerce\Internal\RestApi\Routes\V4
AbstractController::get_route_error_response
Get route response when something went wrong.
Method of the class: AbstractController{}
No Hooks.
Returns
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 ): WP_Error;
- $error_code(string) (required)
- String based error code.
- $error_message(string) (required)
- User facing error message.
- $http_status_code(int)
- HTTP status.
Default: 400 - $additional_data(array)
- Extra data (key value pairs) to expose in the error response.
Default: array()
Changelog
| Since 10.2.0 | Introduced. |
AbstractController::get_route_error_response() AbstractController::get route error response code WC 10.4.3
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 )
)
);
}