addUserError(transaction, error, customAttributes, expected) {
    if (!error) {
      return
    }

    const shouldCollectErrors = this._shouldCollectErrors()
    if (!shouldCollectErrors) {
      logger.trace('error_collector.enabled is false, dropping user reported error.')
      return
    }

    const timestamp = Date.now()
    const exception = new Exception({ error, timestamp, customAttributes, expected })

    if (transaction) {
      transaction.addUserError(exception)
    } else {
      this.collect(transaction, exception)
    }
  }
This function is used to collect errors specifically added using the
`API#noticeError()` method.

Similarly to add(), it collects the error right away when transaction is
not supplied. Otherwise it delays collecting the error until the transaction
ends. The reason for separating the API errors from other exceptions is that
different ignore rules apply to them.

NOTE: this interface is unofficial and may change in future.

@param {?Transaction}  transaction  Transaction associated with the error.
@param {*} error The error passed into `API#noticeError()`
@param {object} customAttributes custom attributes to add to the error
@param {boolean} expected Is the error expected?