Requesting a render for a nonexisting article, such as http://localhost:3030/en.wikipedia.org/v1/pdf/Book13242/letter, generates a PDF with the JSON error codes.
= Actual =
The content is clipped but contains:
```
{"type":"https://mediawiki.org/wiki/HyperSwitch/errors/not_found","title":"Not found.","method":"get","detail":"Page or revision not found
```
= Expected =
HTTP status 404 is returned with an optional text/html payload.
= Developer Notes =
The missing part is response validation before calling [[ https://github.com/wikimedia/mediawiki-services-chromium-render/blob/master/lib/renderer.js#L51 | page.pdf() ]]. Previous promise (`page.goto(url, ...)`) returns a [[ https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#class-response | Response object ]].
Before calling `page.pdf(pdfOptions)` we have to verify that response is successful. We can achieve that by checking `response.ok()` or `response.status() === 200`.
With that approach we will handle not only 404 pages, but also all server error (500 returned by MediaWiki).
Please verify first how the `response` object looks like, as documentation says that for many requests it can return an array of responses. It's possible that for 3xx responses you'll get more than one response object (I did not verify that).
There is one pitfall there, you have to handle 404 error differently than 500, this has to be implemented in [[ https://github.com/wikimedia/mediawiki-services-chromium-render/blob/master/lib/queue.js#L226-L233 | queue.js ]]