Skip to main content

Handling errors

When a publication can't be opened, onPublicationError fires instead of onPublicationReady:

<ReadiumView
file={file}
onPublicationError={(event) => {
console.warn(event.code, event.detail);
setError(event.message);
}}
/>
Field
codeWhy, the same on every platform. Branch on it, or map it to your own localized text.
messageA default English description of code, the same on every platform.
detailThe platform's own description of what went wrong, for logs. It varies by platform.
urlThe file.url that failed.
protectionSchemeFor a protected publication, its DRM scheme's URI.
codemessage
fileNotFoundThe publication file couldn't be found.
formatNotSupportedThis publication's format isn't supported.
openFailedThe publication couldn't be opened.
protectionNotSupportedThis publication is protected with a DRM this app doesn't support.
restrictedAccess to this publication was refused.
cancelledOpening the publication was cancelled.

describePublicationError(code) returns the same message for a code you already have.

Protected publications​

  • protectionNotSupported: no registered content protection handles the publication's DRM. For LCP, install and initialize react-native-readium-lcp.
  • restricted: a protection handles it but refused access, for example an expired loan or a wrong passphrase.
  • cancelled: access was refused without an error, for example when the user dismissed the passphrase prompt.

After restricted or cancelled, setting file again with different credentials retries the open.