diff --git a/packages/guides-graphs/src/Graphs/Renderer/PlantumlServerRenderer.php b/packages/guides-graphs/src/Graphs/Renderer/PlantumlServerRenderer.php index fd9cd4644..fdbb7a528 100644 --- a/packages/guides-graphs/src/Graphs/Renderer/PlantumlServerRenderer.php +++ b/packages/guides-graphs/src/Graphs/Renderer/PlantumlServerRenderer.php @@ -15,6 +15,7 @@ use phpDocumentor\Guides\RenderContext; use Psr\Log\LoggerInterface; +use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; use Symfony\Contracts\HttpClient\HttpClientInterface; use function Jawira\PlantUml\encodep; @@ -35,24 +36,36 @@ public function render(RenderContext $renderContext, string $diagram): string|nu $url = $this->plantumlServerUrl . '/svg/' . $encodedDiagram; - $response = $this->httpClient->request( - 'GET', - $url, - ); + try { + $response = $this->httpClient->request( + 'GET', + $url, + ); + + if ($response->getStatusCode() !== 200) { + $this->logger->warning( + sprintf( + 'Failed to render diagram using url: %s. The server returned status code %s. ', + $url, + $response->getStatusCode(), + ), + $renderContext->getLoggerInformation(), + ); - if ($response->getStatusCode() !== 200) { + return null; + } + + return $response->getContent(); + } catch (TransportExceptionInterface) { $this->logger->warning( sprintf( - 'Failed to render diagram using url: %s. The server returned status code %s. ', + 'Failed to render diagram using url: %s. ', $url, - $response->getStatusCode(), ), $renderContext->getLoggerInformation(), ); return null; } - - return $response->getContent(); } } diff --git a/packages/guides-restructured-text/tests/unit/Parser/Productions/RuleTestCase.php b/packages/guides-restructured-text/tests/unit/Parser/Productions/RuleTestCase.php index 26ce1fc23..1b2a2e171 100644 --- a/packages/guides-restructured-text/tests/unit/Parser/Productions/RuleTestCase.php +++ b/packages/guides-restructured-text/tests/unit/Parser/Productions/RuleTestCase.php @@ -67,7 +67,7 @@ protected function givenInlineMarkupRule(): InlineMarkupRule $inlineTokenParser->method('parse')->willReturnCallback( static fn (string $arg): InlineCompoundNode => new InlineCompoundNode([ new PlainTextInlineNode($arg), - ]) + ]), ); return new InlineMarkupRule($inlineTokenParser); diff --git a/packages/guides-restructured-text/tests/unit/Parser/Productions/SectionRuleTest.php b/packages/guides-restructured-text/tests/unit/Parser/Productions/SectionRuleTest.php index db58310cd..fa5373842 100644 --- a/packages/guides-restructured-text/tests/unit/Parser/Productions/SectionRuleTest.php +++ b/packages/guides-restructured-text/tests/unit/Parser/Productions/SectionRuleTest.php @@ -182,7 +182,7 @@ private function getInlineTokenParserMock(): InlineParser { $inlineTokenParser = $this->createMock(InlineParser::class); $inlineTokenParser->method('parse')->willReturnCallback( - static fn (string $arg): InlineCompoundNode => InlineCompoundNode::getPlainTextInlineNode($arg) + static fn (string $arg): InlineCompoundNode => InlineCompoundNode::getPlainTextInlineNode($arg), ); return $inlineTokenParser; diff --git a/tests/Integration/tests/graphs/plantuml-server-error/expected/index.html b/tests/Integration/tests/graphs/plantuml-server-error/expected/index.html new file mode 100644 index 000000000..ac142e833 --- /dev/null +++ b/tests/Integration/tests/graphs/plantuml-server-error/expected/index.html @@ -0,0 +1,11 @@ + +
+

Uml Directive

+
Figure 1-1: Application flow
+
Figure 1-1: Application flow
+
+ diff --git a/tests/Integration/tests/graphs/plantuml-server-error/expected/logs/warning.log b/tests/Integration/tests/graphs/plantuml-server-error/expected/logs/warning.log new file mode 100644 index 000000000..34e03041a --- /dev/null +++ b/tests/Integration/tests/graphs/plantuml-server-error/expected/logs/warning.log @@ -0,0 +1,2 @@ +app.WARNING: Failed to render diagram using url: https://this-does-not-exist-phpdoc.com/svg/u-9ApaaiBbRGjLF8Byb8BN86ywmKSbEBYnFJKxcu0000. {"rst-file":"index"} [] +app.WARNING: Failed to render diagram using url: https://this-does-not-exist-phpdoc.com/svg/u-9ApaaiBbRGjLF8Byb8BN86ywmKSbEBYnFJKxcu0000. {"rst-file":"index"} [] diff --git a/tests/Integration/tests/graphs/plantuml-server-error/input/Plantuml/something.plantuml b/tests/Integration/tests/graphs/plantuml-server-error/input/Plantuml/something.plantuml new file mode 100644 index 000000000..5ce28e0b9 --- /dev/null +++ b/tests/Integration/tests/graphs/plantuml-server-error/input/Plantuml/something.plantuml @@ -0,0 +1,5 @@ +@startuml + +class -> otherClass : message + +@enduml \ No newline at end of file diff --git a/tests/Integration/tests/graphs/plantuml-server-error/input/guides.xml b/tests/Integration/tests/graphs/plantuml-server-error/input/guides.xml new file mode 100644 index 000000000..c17f96d1b --- /dev/null +++ b/tests/Integration/tests/graphs/plantuml-server-error/input/guides.xml @@ -0,0 +1,9 @@ + + + + plantuml-server + https://this-does-not-exist-phpdoc.com + + diff --git a/tests/Integration/tests/graphs/plantuml-server-error/input/index.rst b/tests/Integration/tests/graphs/plantuml-server-error/input/index.rst new file mode 100644 index 000000000..39982e3d6 --- /dev/null +++ b/tests/Integration/tests/graphs/plantuml-server-error/input/index.rst @@ -0,0 +1,14 @@ +============== +Uml Directive +============== + +.. uml:: /Plantuml/something.plantuml + :align: center + :caption: Figure 1-1: Application flow + :width: 1000 + + +.. uml:: Plantuml/something.plantuml + :align: center + :caption: Figure 1-1: Application flow + :width: 1000