Skip to content

How to catch errors in async persistence adapter registration #1489

Answered by maxnowack
morgs32 asked this question in Q&A
Discussion options

You must be logged in to vote

The persistence.error event is triggered when an error occurs during registration. In your case, implementing a fallback to a different persistence adapter is probably only feasible with a custom adapter. However, this custom adapter could simply wrap existing persistence adapters and act as a proxy. I’m using a similar approach in my project.

Here’s an example how a fallback adapter could look like.

function createFallbackPersistenceAdapter(name: string) {
  let usedAdapter: PersistenceAdapter = createOPFSAdapter(name)
  const initializeFallbackAdapter = () => createLocalStorageAdapter(name)

  return createPersistenceAdapter({
    register: async (...args) => {
      try {
        return 

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by maxnowack
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1432 on March 11, 2025 14:24.