better error handling when pdf generation fail