Skip to content

Commit

Permalink
resolve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
alxndrsn committed Dec 13, 2024
1 parent e750614 commit c71c179
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions packages/node_modules/pouchdb-errors/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ class PouchError extends Error {
super(reason);
this.status = status;
this.name = name;
// TODO this looks pointless:
this.error = true;
}

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit c71c179

Please sign in to comment.