github.com/go-kivik/kivik/v4@v4.3.2/pouchdb/bindings/poucherr/poucherr.inc.js (about)

     1  // Licensed under the Apache License, Version 2.0 (the "License"); you may not
     2  // use this file except in compliance with the License. You may obtain a copy of
     3  // the License at
     4  //
     5  //  http://www.apache.org/licenses/LICENSE-2.0
     6  //
     7  // Unless required by applicable law or agreed to in writing, software
     8  // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
     9  // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
    10  // License for the specific language governing permissions and limitations under
    11  // the License.
    12  
    13  function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
    14  var inherits = _interopDefault(require('inherits'));
    15  inherits(PouchError, Error);
    16  
    17  function PouchError(status, error, reason) {
    18      Error.call(this, reason);
    19      this.status = status;
    20      this.name = error;
    21      this.message = reason;
    22      this.error = true;
    23  }
    24  
    25  PouchError.prototype.toString = function () {
    26      return JSON.stringify({
    27          status: this.status,
    28          name: this.name,
    29          message: this.message,
    30          reason: this.reason
    31      });
    32  };
    33  
    34  $global.ReconstitutePouchError = function(str) {
    35      const o = JSON.parse(str);
    36      Object.setPrototypeOf(o, PouchError.prototype);
    37      return o;
    38  };