Giter Site home page Giter Site logo

ssb-network-errors-archived's Introduction

โš ๏ธ This repo was moved to https://github.com/ssbc/ssb-network-errors. This archival will remain in this GitHub org ssb-ngi-pointer to demonstrate the outcome of the work done by the SSB NGI Pointer team during 2020 and 2021. The SSB NGI Pointer team is no longer active because we completed our grant project.

ssb-network-errors

Detect the severity of a muxrpc error or network connection error to a remote SSB peer.

Muxrpc and packet-stream throw specific errors when the stream terminates. In Node.js these errors have a specific message string. In go-ssb they have another specific message string. This module handles the pattern recognition of those error messages and classifies them with a severity level.

Usage

npm install --save ssb-network-errors

This module is just a function that takes a network error and classifies it with a severity number ranging from 0 to 3.

  • Severity 0: the local peer (us) closed the muxrpc connection with the remote peer gracefully, there is nothing to handle here
  • Severity 1: the remote peer (them) closed the muxrpc connection with us, we MAY have to close or clean up connection details
  • Severity 2: a network error such as TCP or secret-handshake related occurred, may indicate a problem with the user's internet connectivity or authentication issues (related to secret-handshake)
  • Severity 3: any other kind of error that this module cannot classify is labelled with severity 3
const getSeverity = require('ssb-network-errors')
const pull = require('pull-stream')

// rpc is connection to a remote SSB peer
pull(
  rpc.createHistoryStream({ id })
  ssb.createWriteStream((err) => {
    const severity = getSeverity(err)
    if (severity === 0) {
      console.log('we closed the local stream')
      console.log('more details:', err)
    }
    else if (severity === 1) {
      console.log('THEY closed the local stream')
      console.log('more details:', err)
    }
    else if (severity === 2) {
      console.log('a typical TCP or internet error occurred')
      console.log('more details:', err)
    }
    else if (severity === 3) {
      console.log('something truly unexpected happened to the connection')
      console.log('more details:', err)
    }
  })
)

License

LGPL-3.0

ssb-network-errors-archived's People

Contributors

staltz avatar

Watchers

Henry avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.