Errors
Never a bare Error. Every failure carries a code you can branch on.
The shape
JavaScript
import { PdfError, CODES } from 'rasura'
try { await session.replaceText(p.id, range, text)} catch (e) { if (e instanceof PdfError) { e.code // one of CODES e.message // safe to show a user e.detail // what the failing layer said, for a bug report }}detail keeps the underlying cause rather than discarding it. The surface stays free of PDF vocabulary by default, and the escape hatch exists for anyone debugging somebody else’s file.
Recovering
Three codes are worth handling specifically in most applications.
JavaScript
switch (e.code) { case 'encrypted-password-required': return retryWithPassword()
case 'font-unavailable': await doc.registerFont(fallback) return retry()
case 'fidelity-below-required': // The floor cannot be met. Lower it, or tell the user what would be lost. return offerLowerFidelity()}The full list of fourteen, with what each implies, is in the API reference.