Home
Support Forums

NPM Fetch Error

Sitename: nurun

Why would I be seeing this in the logs for one of my functions…

10:24:09 PM: c6bea290 ERROR Unable to check new driver version
10:24:09 PM: c6bea290 ERROR FetchError: request to https://registry.npmjs.org/faunadb failed, reason: Client network socket disconnected before secure TLS connection was established at ClientRequest. (/var/task/node_modules/node-fetch/lib/index.js:1461:11) at ClientRequest.emit (events.js:314:20) at TLSSocket.socketErrorListener (_http_client.js:427:9) at TLSSocket.emit (events.js:314:20) at emitErrorNT (internal/streams/destroy.js:92:8) at emitErrorAndCloseNT (internal/streams/destroy.js:60:3) at processTicksAndRejections (internal/process/task_queues.js:84:21) { type: 'system', errno: 'ECONNRESET', code: 'ECONNRESET' }

Hi @markgarrigan,

Could you provide some context as to what you’re trying to do. I told you in the helpdesk, to help us help you. Please provide some code or a repo where we can see what might be causing this.

Here is the relevant code…

const faunadb = require('faunadb')

const order = (a, b) => {
  return a.data ? a.data.order - b.data.order : a.order - b.order
}

const DB = new faunadb.Client({
  secret: process.env.FAUNA_KEY
})

const {
  Ref,
  Paginate,
  Get,
  Match,
  Intersection,
  Select,
  Index,
  Create,
  Update,
  Collection,
  Join,
  Call,
  Lambda,
  Var,
  Map,
  Union,
  Function: Fn,
} = faunadb.query;

const merge = async (ands) => {
  const { data } = await DB.query(Map(
    Paginate(
      Intersection(
        ands.map(({ index, search }) => {
          return Match(Index(index), search)
        })
      )
    ),
    Lambda("X", Get(
      Var("X")
    ))
  ))
  return data
}

const all = async (index) => {
  const { data } = await DB.query(Map(
    Paginate(
      Match(
        Index(index)
      )
    ),
    Lambda("X", Get(
      Var("X")
    ))
  ))
  return data.sort(order)
}

const some = async (index, search) => {
  const { data } = await DB.query(Map(
    Paginate(
      Match(
        Index(index), search
      )
    ),
    Lambda("X", Get(
      Var("X")
    ))
  ))
  return data.sort(order)
}

const includes = async (index, searches) => {
  const { data } = await DB.query(Map(
    Paginate(
      Union(
        searches.map(search => {
          return Match(
            Index(index), search
          )
        })
      )
    ),
    Lambda("X", Get(
      Var("X")
    ))
  ))
  return data.sort(order)
}

const one = async (index, search) => {
  const { data } = await DB.query(Map(
    Paginate(
      Union(
        Match(
          Index(index), search
        )
      )
    ),
    Lambda("X", Get(
      Var("X")
    ))
  ))
  return data.length ? data[0] : data
}

const add = async (collection, obj) => {
  const doc = await DB.query(Create(Collection(collection), { data: obj }))
  return doc
}

const update = async (collection, ref, obj) => {
  const doc = await DB.query(Update(Ref(Collection(collection), ref), { data: obj }))
  return doc
}

module.exports = {
  merge,
  one,
  all,
  some,
  includes,
  add,
  update,
  order
}

That db.js module is then required here…

const stripe = require('stripe')(process.env.STRIPE_SECRET_KEY)
const db = require('./db')

...

await db.add('registrations', session)

I assume you’re using faunadb 4.3.0 because their changelog says that they added this version check in 4.3.0: Release 4.3.0 · fauna/faunadb-js · GitHub

I think the current solution would be to downgrade to faunadb 4.2.0 package and keep an eye on Add option to skip driver version check? · Issue #502 · fauna/faunadb-js · GitHub to see when they release the new version.