Generate the XML-RPC fault response.

@param Exception|Throwable $ex The exception.
@param int $faultcode The faultCode to be included in the fault response
@return string The XML-RPC fault response xml containing the faultCode and faultString.
497792
protected function generate_error($ex, $faultcode = 404) {
        $error = $ex->getMessage();

        if (!empty($ex->errorcode)) {
            // The faultCode must be an int, so we obtain a hash of the errorcode then get an integer value of the hash.
            $faultcode = base_convert(md5($ex->errorcode), 16, 10);

            // We strip the $code to 8 digits (and hope for no error code collisions).
            // Collisions should be pretty rare, and if needed the client can retrieve
            // the accurate errorcode from the last | in the exception message.
            $faultcode = substr($faultcode, 0, 8);

            // Add the debuginfo to the exception message if debuginfo must be returned.
            if (debugging() and isset($ex->debuginfo)) {
                $error .= ' | DEBUG INFO: ' . $ex->debuginfo . ' | ERRORCODE: ' . $ex->errorcode;
            } else {
                $error .= ' | ERRORCODE: ' . $ex->errorcode;
            }
        }

        $fault = array(
            'faultCode' => (int) $faultcode,
            'faultString' => $error
        );

        $encodingoptions = array(
            "encoding" => "UTF-8",
            "verbosity" => "no_white_space",
            // See MDL-54868.
            "escaping" => ["markup"]
        );

        return xmlrpc_encode_request(null, $fault, $encodingoptions);
    }
1265893
public static function withErrorCodeAndParam($errorCode, $message, $parameter, $innerException = null)
	{
		$ex = XPath2Exception::withErrorCodeAndParams( $errorCode, $message, array( $parameter ), $innerException );
		// $ex->ErrorCode = $errorCode;
		return $ex;
	}
187154
public function assertResponseCodeIs($code) {
        $this->requireResponse();

        try {
            Assertion::same(
                $actual = $this->response->getStatusCode(),
                $expected = $this->validateResponseCode($code),
                sprintf('Expected response code %d, got %d.', $expected, $actual)
            );
        } catch (AssertionFailure $e) {
            throw new AssertionFailedException($e->getMessage());
        }
    }
1080536
public static function getMessageFromCode($code)
    {
        if (!array_key_exists($code, self::$responseCodes)) {
            throw new \Exception('The header code '.$code.' is not valid.');
        }

        return self::$responseCodes[$code];
    }
680134
public function generate(Exception $exception, string $id, int $code)
    {
        $errors = $this->path ? json_decode(file_get_contents($this->path), true) : [500 => ['name' => 'Internal Server Error', 'message' => 'An error has occurred and this resource cannot be displayed.']];

        if (isset($errors[$code])) {
            $info = array_merge(['id' => $id, 'code' => $code], $errors[$code]);
        } else {
            $info = array_merge(['id' => $id, 'code' => 500], $errors[500]);
        }

        if ($exception instanceof HttpExceptionInterface) {
            $msg = (string) $exception->getMessage();
            $info['detail'] = (strlen($msg) > 4) ? $msg : $info['message'];
            $info['summary'] = (strlen($msg) < 36 && strlen($msg) > 4) ? $msg : 'Houston, We Have A Problem.';
        } else {
            $info['detail'] = $info['message'];
            $info['summary'] = 'Houston, We Have A Problem.';
        }

        unset($info['message']);

        return $info;
    }
883298
public function convertResultCodeToString($resultCode)
    {
        switch ($resultCode) {
            case TestResult::SKIPPED:
                return 'skipped';
            case TestResult::PENDING:
                return 'pending';
            case TestResult::FAILED:
                return 'failed';
            case StepResult::UNDEFINED:
                return 'undefined';
        }

        return 'passed';
    }
1003165
final public static function exceptionDriver (int $errorCode=NULL)
	{
		switch ($errorCode) {
			case self::EMPTY_VALUE:
				throw new ErrorHandler("Empty Value.", ErrorCode::EMPTY_VALUE);
				break;
			case self::INVALID:
				throw new ErrorHandler("Value Not Valid.", ErrorCode::INVALID);
				break;
			case self::EMPTY_METHOD:
				throw new ErrorHandler("Method not parsed in RouterEngine.", ErrorCode::EMPTY_METHOD);
				break;
			case self::EMPTY_ARGUMENT:
				throw new ErrorHandler("Argument not parsed to method in RouterEngine.", ErrorCode::EMPTY_ARGUMENT);
				break;
			case self::INVALID_DIR:
				throw new ErrorHandler("Specified directory is invalid.", ErrorCode::INVALID_DIR);
				break;
			default:
				throw new ErrorHandler('Error Not Defined.', ErrorCode::THROW_NONE);
				break;
		}
		return;
	}
286185
private function convertToGoogleException($ex)
    {
        switch ($ex->getCode()) {
            case Code::INVALID_ARGUMENT:
                $exception = Exception\BadRequestException::class;
                break;

            case Code::NOT_FOUND:
            case Code::UNIMPLEMENTED:
                $exception = Exception\NotFoundException::class;
                break;

            case Code::ALREADY_EXISTS:
                $exception = Exception\ConflictException::class;
                break;

            case Code::FAILED_PRECONDITION:
                $exception = Exception\FailedPreconditionException::class;
                break;

            case Code::UNKNOWN:
                $exception = Exception\ServerException::class;
                break;

            case Code::INTERNAL:
                $exception = Exception\ServerException::class;
                break;

            case Code::ABORTED:
                $exception = Exception\AbortedException::class;
                break;

            case Code::DEADLINE_EXCEEDED:
                $exception = Exception\DeadlineExceededException::class;
                break;

            default:
                $exception = Exception\ServiceException::class;
                break;
        }

        $metadata = [];
        if ($ex->getMetadata()) {
            foreach ($ex->getMetadata() as $type => $binaryValue) {
                if (!isset($this->metadataTypes[$type])) {
                    continue;
                }
                $metadataElement = new $this->metadataTypes[$type];
                $metadataElement->mergeFromString($binaryValue[0]);
                $metadata[] = $this->serializer->encodeMessage($metadataElement);
            }
        }

        return new $exception($ex->getMessage(), $ex->getCode(), $ex, $metadata);
    }
305915
private function createErrorResponse(int $code, Socket $socket): \Generator
    {
        try {
            yield from $this->log->log(
                Log::NOTICE,
                'Error reading request from %s:%d (Status Code: %d)',
                $socket->getRemoteAddress(),
                $socket->getRemotePort(),
                $code
            );

            $response = $this->handler->onError($code, $socket);

            if ($response instanceof \Generator) {
                $response = yield from $response;
            } elseif ($response instanceof Awaitable) {
                $response = yield $response;
            }

            if (!$response instanceof Response) {
                throw new InvalidResultError(sprintf(
                    'A %s object was not returned from %::onError().',
                    Response::class,
                    get_class($this->handler)
                ), $response);
            }
        } catch (Throwable $exception) {
            yield from $this->log->log(
                Log::ERROR,
                "Uncaught exception when creating response to an error from %s:%d on %s:%d in file %s on line %d: %s",
                $socket->getRemoteAddress(),
                $socket->getRemotePort(),
                $socket->getLocalAddress(),
                $socket->getLocalPort(),
                $exception->getFile(),
                $exception->getLine(),
                $exception->getMessage()
            );
            $response = yield from $this->createDefaultErrorResponse(500);
        }

        return $response;
    }
1247846
public function getError($errorCode) {
        if (array_key_exists($errorCode, $this->_errors)) {
            $result = $this->_errors[$errorCode];
            return $result;
        } else {
            return null;
        }
    }
1346733
protected function getErrorMessage($errorCode)
    {
        if (!isset($this->errorMessageMatrix[$errorCode])) {
            $this->errorMessageMatrix[$errorCode] = 'ERROR_MSG_UNKNOWN';
        }

        // if additional information exist -> add it here
        if ($this->info) {
            if (is_string($this->info)) {
                $this->errorMessageMatrix[$errorCode] .= ' '.$this->info;
            } elseif (count($this->info) != 1 || $this->info[0] != null) {
                foreach ($this->info as $info) {
                    $info = serialize($info);
                    $this->errorMessageMatrix[$errorCode] .= ' '.$info;
                }
            }
        }

        // Return constructed error message
        return $this->errorMessageMatrix[$errorCode];
    }
694831
public function logException(\Exception $ex,$prefix="ex")
    {
        $this->log($ex->getCode().":".$ex->getMessage()."\r\n".$ex->getTraceAsString(),get_class($ex),$prefix);
    }
340217
public static function getReturnTypeFromCode($code, $selfEdit) {
		$url = MoufReflectionProxy::getLocalUrlToProject()."src/direct/return_type_from_code.php";

	
		$response = self::performRequest($url,
		[
			"selfedit"=>($selfEdit)?"true":"false",
			"code" => $code
		]);
	
		$obj = @unserialize($response);
	
		if ($obj === false) {
			throw new Exception($response);
		}
	
		return $obj["data"]["class"];
	}
225324
private function getErrorPageResponse(\Exception $exception, $statusCode)
    {
        $parameter = $this->application->getContainer()->getParameter('error.default');
        if ($this->application->getContainer()->hasParameter('error.'.$statusCode)) {
            $parameter = $this->application->getContainer()->getParameter('error.'.$statusCode);
        }

        $view = $this->getErrorTemplate($parameter);

        return new Response($this->renderer->partial($view, ['error' => $exception]), $statusCode);
    }
380072
public function encodeError($error_code, $error_message) {

        $payload  = '<?xml version="1.0" encoding="'.$this->encoding.'"?>';
        $payload .= "<methodResponse>";
        $payload .= $this->encodeFault($error_code, $error_message);
        $payload .= "</methodResponse>";

        return $payload;

    }
772599
public function convert(\Exception $ex)
    {
        $exceptions = array();

        do {
            $exceptions[] = $this->convertException($ex);
        } while (null !== $ex = $ex->getPrevious());

        return $exceptions;
    }
259260
public static function writeException(\Exception $ex)
	{
		$response = array(
			'exception' => get_class($ex),
			'message' => $ex->getMessage(),
			'code' => $ex->getCode(),
		);
		static::writeJson($response);
	}