Returns a value if an error occurred
@param string|array $key
@param mixed $return_error
@param mixed $return_no_error
@return mixed
544732
public function error($key = null, $return_error = null, $return_no_error = '')
    {
        if (isset($key)) {
            $result = gplcart_array_get($this->errors, $key);
        } else {
            $result = empty($this->errors) ? null : $this->errors;
        }

        if (isset($result)) {
            return isset($return_error) ? $return_error : $result;
        }

        return $return_no_error;
    }
1198019
protected final function setError($key, $error = null){
        if($e = $this->getDefinitionValue($key,'error')){
            $error = $e;
        } else if($error === null){
            $error = sprintf($this->defaultErrorMessage,$key);
        }//elif
        $this->errors[$key] = $error;
        return false;
    }
405488
public function isError($key = null)
    {
        $value = $this->getError($key);
        return is_array($value) ? !empty($value) : isset($value);
    }
1272476
public function addError($error, $key = null)
    {
        if (is_string($error)) {
            $error = new Exception($error);
        } elseif ($error instanceof Exception) {
            // Nothing to do
        } else {
            throw new Exception('only string errors or instances of Exception can be added');
        }

        if ($key) {
            $this->errors[$key] = $error;
        } else {
            $this->errors[] = $error;
        }

        return false;
    }
412093
public static function key($key, $array, $returnValue = false)
    {
        $isExists = array_key_exists((string)$key, (array)$array);

        if ($returnValue) {
            if ($isExists) {
                return $array[$key];
            }

            return null;
        }

        return $isExists;
    }
804307
public function returnOrSet($key, $default = null)
    {
        if ($this->offsetExists($key)) {
            return $this->offsetGet($key);
        }
        $this->offsetSet($key, $default);

        return $default;
    }
472282
function notFoundError(key) {
  var error = new Error(`Key not found in database: ${key}`);

  error.name = 'NotFoundError';
  error.key = key;
  return error;
}
828254
public function getErrors($key = null, $group = null)
    {
        return $this->validator->getErrors($key, $group);
    }
841497
public function getErrorData($key = null)
    {
        if ($this->isSuccessful()) {
            return null;
        }
        // get error data (array in data)
        $data = isset($this->getData('data')[0]) ? $this->getData('data')[0] : null;
        if ($key) {
            return isset($data[$key]) ? $data[$key] : null;
        }
        return $data;
    }
164078
public function hasErrors($key = NULL)
    {
        if ($key) {
            return isset($this[$key]);
        } else {
            if (count($this)) {
                return true;
            } else {
                return false;
            }
        }
    }
388389
public function getError($key, $index = null, $group = null)
    {
        return $this->validator->getError($key, $index, $group);
    }
287619
public function setError($error, $key=null)
	{
		if ($key !== null)
		{
			$this->_errors[$key] = $error;
		}
		else
		{
			array_push($this->_errors, $error);
		}
		return $this;
	}
970750
public function return_data($data){

        if (isset($data['errcode']) && $data['errcode'] > 0){
            $this->error = $data['errmsg'];
            return false;
        }else{
            return $data;
        }
    }
871922
public function setError($key, $value)
    {
        if (isset($key)) {
            gplcart_array_set($this->errors, $key, $value);
        } else {
            $this->errors = (array) $value;
        }

        return $this->errors;
    }
9495
public function add_error( $key, $_errors ) {
		if ( ! $_errors || ! $this->errors instanceof WP_Error ) {
			return;
		}

		if ( ! $this->fields->has( $key ) ) {
			return;
		}

		foreach ( is_array( $_errors ) ? $_errors : [ $_errors ] as $message ) {
			$this->errors->add( $key, $message );
		}
	}
1358727
protected function isError($key = null)
    {
        if (!isset($key)) {
            return !empty($this->errors);
        }

        $result = $this->getError($key);
        return !empty($result);
    }
515402
static function flattenErrors($obj, $key = '') {
        $messages = array();
        
        foreach($obj as $k => $val) {
            if($k === 'message') {
                continue;
            }
            
            $newKey = $k;
            if($key) {
                if(\is_numeric($k)) {
                    $newKey = $key.'.'.$k;
                } else {
                    $newKey = $key.'['.$k.']';
                }
            }
            
            if(isset($val['_errors'])) {
                $messages[] = $newKey.': '.\implode(' ', \array_map(function ($element) {
                    return $element['message'];
                }, $val['_errors']));
            } else if(isset($val['code']) || isset($val['message'])) {
                $messages[] = \trim(($val['code'] ?? '').': '.($val['message'] ?? ''));
            } else if(\is_array($val)) {
                $messages = \array_merge($messages, self::flattenErrors($val, $newKey));
            } else {
                $messages[] = $val;
            }
        }

        return $messages;
    }