Tidy up error handling for generatePreviewPdf.