Set errors from response

@param  array  $response
@param  string  $key
@return void
192791
protected function setErrors($response, $key)
    {
        foreach ($response->{$key} as $error) {
            $this->setError($error->code, $error->description);
        }
    }
287619
public function setError($error, $key=null)
	{
		if ($key !== null)
		{
			$this->_errors[$key] = $error;
		}
		else
		{
			array_push($this->_errors, $error);
		}
		return $this;
	}
1222126
public function add_error( $key, $message )
	{
		$this->success = false;
		$this->errors[$key][] = $message;
	}
1292309
@Override
  public final void error(String key, String error) throws IOException {
    if (key != null) {
      add(key, false);
      setError(newCurrentPosition, error, newCurrentExisting);
    }
  }
1309254
public function offsetSet($key, $value){
        if ( is_array($value) )
          parent::offsetSet($key, new static($value));
        else
          parent::offsetSet($key, $value);
    }
88877
public function set(string $key, $value)
    {
        if (!is_array($value)) {
            $value = [$value];
        }
        $this->data[$key] = $value;
    }
1246170
protected function evaluateResponse(array $response) {
        if (array_key_exists('error', $response) &&
            $response['error'] !== null) {
            // Validate error object:
            if (!is_array($response['error'])) {
                throw new RuntimeException('Invalid error object');
            }

            if (!array_key_exists('code', $response['error']) ||
                !is_int($response['error']['code']) ||
                $response['error']['code'] >= 0) {
                throw new RuntimeException('Invalid error code');
            }

            if (!array_key_exists('message', $response['error']) ||
                !is_string($response['error']['message']) ||
                strlen($response['error']['message']) === 0) {
                throw new RuntimeException('Invalid error message');
            }

            $details = [];

            if (array_key_exists('data', $response['error']) &&
                is_array($response['error']['data'])) {
                foreach ($response['error']['data'] as $topic => $description) {
                    $text = 'unknown';

                    switch (gettype($description)) {
                        case 'array':
                            $text = implode('; ', $description);
                            break;
                        case 'string':
                            $text = $description;
                            break;
                    }

                    $details[] = sprintf(
                        '%s: %s',
                        $topic,
                        $text
                    );
                }
            }

            if (count($details) > 0) {
                $message = sprintf(
                    'i-doit responded with an error: %s [%s]',
                    $response['error']['message'],
                    implode('; ', $details)
                );
            } else {
                $message = sprintf(
                    'i-doit responded with an error: %s',
                    $response['error']['message']
                );
            }

            throw new RuntimeException(
                $message,
                $response['error']['code']
            );
        }

        if (!array_key_exists('result', $response)) {
            throw new RuntimeException('i-doit forgot to add a result to its response.');
        }

        return $this;
    }
138940
private function triggerError($error, Http\Request $request, Http\Response $response)
    {
        if (! isset($this->options['onerror'])
            || ! is_callable($this->options['onerror'])
        ) {
            return;
        }

        $onError = $this->options['onerror'];
        $onError($error, $request, $response);
    }
146753
protected function handleError($response)
    {
        $message = $response['responseCode'].' ('.$response['errorId'].'): '.$response['message'];
        $this->throwNotSentException($message, $response['errorId']);
    }
164078
public function hasErrors($key = NULL)
    {
        if ($key) {
            return isset($this[$key]);
        } else {
            if (count($this)) {
                return true;
            } else {
                return false;
            }
        }
    }
525279
public function add($error, $key = NULL)
    {
        if ($key) {
            $errorContainer = $this->get($key, new static());
            $errorContainer->push($error);
            $this[$key] = $errorContainer;
        } else {
            $this->push($error);
        }
    }
1320686
protected function setNeededAction(Response $response) {
        if ($response->hasHtml())
        {
            $response->setNeededAction(Response::NEEDED_SHOW_HTML);
        }
        elseif ($response->isProcessing())
        {
            $response->setNeededAction(Response::NEEDED_STATUS_UPDATE);
        }
    }
439684
public function setResponse($response)
    {
        $xml = simplexml_load_string($response);
        if (!empty($xml->error)) {
            $this->message = (string) $xml->error;
        }
    }
519799
public static function setError($id, $errors, $element = "")
    {
        if (!is_array($errors)) {
            $errors = array($errors);
        }

        if (empty($_SESSION["form"][$id]["errors"][$element])) {
            $_SESSION["form"][$id]["errors"][$element] = array();
        }

        foreach ($errors as $error) {
            $_SESSION["form"][$id]["errors"][$element][] = $error;
        }
    }
1007945
public function setErrors(array $errors, string $key = null, string $group = null): self
    {
        if (!empty($group)) {
            if (!empty($key)) {
                $this->errors[$group][$key] = $errors;
            } else {
                $this->errors[$group] = $errors;
            }
        } elseif (!empty($key)) {
            $this->errors[$key] = $errors;
        } else {
            $this->errors = $errors;
        }

        return $this;
    }
547244
protected function setData($key, $value)
    {
        $this->data[$key] = (is_array($value)) ? $value : [$value];
    }
1059731
private function wpErrorFor(array $errors, array $response): WP_Error
    {
        $wpError = new WP_Error;
        foreach ($errors as $error) {
            $wpError->add($error['code'], $error['message'], $response);
        }

        return $wpError;
    }