public static function addError($messageOrException = 'UNKNOWN', $key = null)
    {
        $formId = Actions::DEFAULT_ERRORS_ID;
        $actionQueryString = Request::getInputValue("do", false, true);
        
        if (!empty($actionQueryString)) {
            $actionQuery = self::parseActionQueryString($actionQueryString);
            $formId = $actionQuery->formId ?? $formId;
        }
        
        if (!array_key_exists($formId, self::$formErrorCache)) {
            self::$formErrorCache[$formId] = array();
        }
        
        if (is_string($messageOrException)) {
            $message = $messageOrException;
            
            $messageOrException = new \stdClass();
            $messageOrException->message = $message;
        }
        else if($messageOrException instanceof \Exception) {
            $readableMessageOrException = new \stdClass();
            
            // include default \Exception fields
            $readableMessageOrException->code = $messageOrException->getCode();
            $readableMessageOrException->message = $messageOrException->getMessage();
            $readableMessageOrException->trace = $messageOrException->getTrace();
            $readableMessageOrException->traceAsString = $messageOrException->getTraceAsString();
            $readableMessageOrException->file = $messageOrException->getFile();
            $readableMessageOrException->line = $messageOrException->getLine();
              
            // include any other accessible fields
            foreach ($messageOrException as $field => $value) {
                $readableMessageOrException->$field = $value;
            }
            
            $messageOrException = $readableMessageOrException;
        }
        
        if ($key !== null) {
            self::$formErrorCache[$formId][$key] = $messageOrException;
        }
        else {
            self::$formErrorCache[$formId][] = $messageOrException;
        }
        
        Cache::getInstance(FlashCache::CACHE_INSTANCE_NAME)->cache($formId, json_encode(self::$formErrorCache[$formId]));
    }