What is the best way to wrap PouchDB?

41 views
Skip to first unread message

Alexander Harm

unread,
Mar 9, 2016, 4:13:28 AM3/9/16
to PouchDB
Hello,

I would like to wrap PouchDB in order to treat 401s separately. I had something like this in mind:

export class MyPouch extends PouchDB {

  constructor (name: string, options: any) {
   super(name, options)
 }
 
 // wrapping get
 get (id: string): any {
   
   return super
   .get(id)
   .catch((err) => {
     if (err.status === 401) {
       // do something else
     }
     return Promise.reject(err)
   })
   
 }
}

While this works more or less during normal operations replication fails. I guess PouchDB treats the errors it receives when checking for checkpoints in a specific way. Can someone point me in the right direction?

Thanks, Alexander

Nolan Lawson

unread,
Mar 16, 2016, 1:39:45 PM3/16/16
to PouchDB
There isn't really an easy way to do this. If you're feeling adventurous, you can look at the code in https://github.com/nolanlawson/transform-pouch and see if you can borrow any of it to try to do what you want.

The best solution in this case may be a proxy on the server to transform your requests as needed.

Cheers,
Nolan
Reply all
Reply to author
Forward
0 new messages