Skip to content

Commit

Permalink
fix(pouchdb-error): do not inherit error properties by copying from p…
Browse files Browse the repository at this point in the history
…arent error manually

to avoid Hermes from causing an error. See facebook/hermes#1496
  • Loading branch information
craftzdog committed Dec 4, 2024
1 parent 67fcfeb commit 5db0171
Showing 1 changed file with 6 additions and 19 deletions.
25 changes: 6 additions & 19 deletions packages/node_modules/pouchdb-errors/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,13 @@ var MISSING_STUB = new PouchError(412, 'missing_stub', 'A pre-existing attachmen
var INVALID_URL = new PouchError(413, 'invalid_url', 'Provided URL is invalid');

function createError(error, reason) {
function CustomPouchError(reason) {
// inherit error properties from our parent error manually
// so as to allow proper JSON parsing.
var names = Object.getOwnPropertyNames(error);
for (var i = 0, len = names.length; i < len; i++) {
if (typeof error[names[i]] !== 'function') {
this[names[i]] = error[names[i]];
}
}

if (this.stack === undefined) {
this.stack = (new Error()).stack;
}

if (reason !== undefined) {
this.reason = reason;
}
// inherit error properties from our parent error manually
// so as to allow proper JSON parsing.
var err = new PouchError(error.status, error.name, error.message);
if (reason !== undefined) {
err.reason = reason;
}
CustomPouchError.prototype = PouchError.prototype;
return new CustomPouchError(reason);
return err;
}

function generateErrorFromResponse(err) {
Expand Down

0 comments on commit 5db0171

Please sign in to comment.