diff --git a/packages/node_modules/pouchdb-errors/src/index.js b/packages/node_modules/pouchdb-errors/src/index.js index d36c63bf11..d4b79cf630 100644 --- a/packages/node_modules/pouchdb-errors/src/index.js +++ b/packages/node_modules/pouchdb-errors/src/index.js @@ -3,7 +3,6 @@ class PouchError extends Error { super(reason); this.status = status; this.name = name; - // TODO this looks pointless: this.error = true; } @@ -42,15 +41,24 @@ const FILE_EXISTS = { status:412, name:'file_exists', message:'The database coul const MISSING_STUB = { status:412, name:'missing_stub', message:'A pre-existing attachment stub wasn\'t found' }; const INVALID_URL = { status:413, name:'invalid_url', message:'Provided URL is invalid' }; +const PROTECTED_PROPS = new Set([ + 'status', + 'name', + 'message', + 'reason', + 'stack', +]); + function createError(error, reason) { const pouchError = new PouchError(error.status, error.name, error.message); // inherit error properties from our parent error manually // so as to allow proper JSON parsing. for (const name of Object.getOwnPropertyNames(error)) { - if (typeof error[name] !== 'function' && name !== 'message' && name !== 'status' && name !== 'error' && name !== 'name' && name !== 'stack') { - pouchError[name] = error[name]; + if (typeof error[name] === 'function' || PROTECTED_PROPS.has(name)) { + continue; } + pouchError[name] = error[name]; } if (reason !== undefined) {