/**
  * @param GatewayModuleException $exception
  * @return GatewayModule
  */
 protected function _onErrorRawResponseEmitFailed(GatewayModuleException $exception)
 {
     $result = $this;
     // no valid request raw data
     $isDebugEnabled = $this->getIsDebugEnabled();
     $isAutoEmitResponseEnabled = $this->getIsAutoEmitResponseEnabled();
     if ($isAutoEmitResponseEnabled) {
         $responseData = array('result' => null, 'error' => RpcUtil::exceptionAsArray($exception, $isDebugEnabled));
         $responseText = RpcUtil::jsonEncode($responseData, false);
         if (!is_string($responseText)) {
             $responseData = array('result' => null, 'error' => RpcUtil::exceptionAsArray($exception, false));
             $responseText = RpcUtil::jsonEncode($responseData, false);
         }
         $headersList = array('HTTP/1.1 500 Internal Server Error');
         $this->_emitResponseHeaders($headersList);
         echo (string) $responseText;
         return $result;
     }
     return $result;
 }