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 page.pdf(). Previous promise (page.goto(url, ...)) returns a 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 be able to handle all errors - including the 5xx returned by MediaWiki.
There is one pitfall: you have to handle 404 errors differently than 400|5xx, this has to be implemented in queue.js
QA Steps
Please try to generate a PDF for non-existing article, for example: http://chromium-pdf.wmflabs.org/en.wikipedia.org/v1/pdf/ArticleThatDoesntExist/letter
Service should return application/json with HTTP_404 error instead of PDF containing Article not found text