export class NotFoundError extends Error {
  constructor (message, options) {
    super(message, options)
    this.status = options.status
  }
}

export class VersionMismatchError extends Error {}

/**
 * Returns true, if the error is a VersionMismatchError or if the error is an aggregate error containing a VersionMismatchError
 * @param {AggregateError | Error} err
 * @return boolean
 */
export function isVersionMismatchError (err) {
  const errors = err instanceof AggregateError ? err.errors : [err]
  return errors.reduce((memo, error) => memo && error instanceof VersionMismatchError, true)
}

/**
 * Returns true, if the error is a NotFoundError or if the error is an aggregate error containing a NotFoundError
 * @param {AggregateError | Error} err
 * @return boolean
 */
export function isNotFoundError (err) {
  const errors = err instanceof AggregateError ? err.errors : [err]
  return errors.reduce((memo, error) => memo && error instanceof NotFoundError, true)
}