WC_API_Server::error_to_array( WP_Error $error )

Convert an error to an array


Description Description

This iterates over all error codes and messages to change it into a flat array. This enables simpler client behaviour, as it is represented as a list in JSON rather than an object/map


Parameters Parameters

$error

(Required)


Top ↑

Return Return

(array) List of associative arrays with code and message keys


Top ↑

Source Source

File: includes/legacy/api/v2/class-wc-api-server.php

	protected function error_to_array( $error ) {
		$errors = array();
		foreach ( (array) $error->errors as $code => $messages ) {
			foreach ( (array) $messages as $message ) {
				$errors[] = array( 'code' => $code, 'message' => $message );
			}
		}

		return array( 'errors' => $errors );
	}

Top ↑

Changelog Changelog

Changelog
Version Description
2.1 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.