carlos-jenkins / plantweb

Plantweb is a Python client for the PlantUML server -
https://plantweb.readthedocs.io/
Apache License 2.0
27 stars 15 forks source link

Make render fail if server returns an error #12

Open carlos-jenkins opened 7 years ago

carlos-jenkins commented 7 years ago

Splitting from #7

Currently the call to the PlantUML server asserts that the servers returns a non-error HTTP code:

https://github.com/carlos-jenkins/plantweb/blob/bf4eec5021a6f75e9fb3bcb34bec7b6cd8bb9dc8/lib/plantweb/plantuml.py#L123

Nevertheless, PlantUML reports always 200 OK even if the diagram fails to render. Errors are reported by the X-PlantUML-Diagram-Error response header.

For example:

$ curl -D - http://www.plantuml.com/plantuml/png/AqWiAibCpYp8Ar58v7BAJrBGLN3CoKnELR1Io4ZDoSa70000 -o /dev/null
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Content-Type: image/png
Expires: Tue, 18 Jul 2017 19:16:17 GMT
Date: Thu, 13 Jul 2017 19:16:17 GMT
Last-Modified: Mon, 03 Jul 2017 17:45:00 GMT
Cache-Control: public, max-age=432000
ETag: "1911Fn0eonQKK9-foqoXNnSom00"
X-PlantUML-Diagram-Description: (Error)
X-PlantUML-Diagram-Error: Syntax Error?
X-PlantUML-Diagram-Error-Line: 1
X-PlantUML-Diagram-Error: Syntax Error?
X-PlantUML-Diagram-Error-Line: 1
X-PlantUML-Diagram-Error: Syntax Error?
X-PlantUML-Diagram-Error-Line: 1
X-Powered-By: PlantUML Version 1.2017.16beta1
X-Patreon: Support us on http://plantuml.com/patreon
X-Donate: http://plantuml.com/paypal
X-Quote: You have died of dysentery.
X-PlantUML-Measure: 1/56/171
X-PlantUML-Diagram-Width: 565
X-PlantUML-Diagram-Height: 309
Content-Length: 15327
Server: PlantUML/0.6
Proxy-Connection: Keep-Alive
Connection: Keep-Alive
Age: 569

100 15327  100 15327    0     0  20757      0 --:--:-- --:--:-- --:--:-- 20768

So, in other words, change logic to assert presence of this headers.

carlos-jenkins commented 7 years ago

This is how a successfully rendered image looks like:

$ curl -D - http://www.plantuml.com/plantuml/png/SyfFKj2rKt3CoKnELR1Io4ZDoSa70000 -o /dev/null
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0HTTP/1.1 200 OK
Expires: Wed, 10 Jan 2018 01:04:48 GMT
Last-Modified: Tue, 22 Dec 2009 00:00:00 GMT
Cache-Control: public
Access-Control-Allow-Origin: *
Content-Type: image/png
Server: PlantUML/0.6
Transfer-Encoding: chunked
Proxy-Connection: Keep-Alive
Connection: Keep-Alive
Age: 15965174
Date: Thu, 13 Jul 2017 19:51:03 GMT

100  2187    0  2187    0     0   5864      0 --:--:-- --:--:-- --:--:--  5879