cozy-labs/cozy-desktop

View on GitHub
core/pouch/error.js

Summary

Maintainability
A
55 mins
Test Coverage
/**
 * @module core/pouch/error
 * @flow
 * */

/** Represents an Error as returned by Pouch when saving a document
 *
 * Some errors will not be returned as such since they're treated differently by
 * Pouch itself.
 * Examples include:
 * - 'bad_format', thrown when a doc's _rev attribute's format is bad
 */
class PouchError extends Error {
  /*::
  name: string
  status: number
  message: string
  */

  constructor(
    {
      name,
      status,
      message
    } /*:{ name: string, status: number, message: string } */
  ) {
    super(message)

    if (Error.captureStackTrace) {
      Error.captureStackTrace(this, PouchError)
    }

    this.name = name
    this.status = status
  }

  toString() {
    return `(${this.status}) ${this.name}: ${this.message}`
  }
}

module.exports = { PouchError }