# ssb-network-errors

> Detect various muxrpc and network errors between SSB peers

Latest version **1.0.1** (published 2021-10-08) · LGPL-3.0 license · 0 weekly downloads

## Install

```sh
npm install ssb-network-errors
pnpm add ssb-network-errors
yarn add ssb-network-errors
bun add ssb-network-errors
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2021-10-08 |
| First published | 2021-06-18 |
| Weekly downloads | 0 |
| License | LGPL-3.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 19.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Andre Staltz |
| Maintainers | staltz |

## Links

- npm: https://www.npmjs.com/package/ssb-network-errors
- Repository: https://github.com/ssb-ngi-pointer/ssb-network-errors
- Issues: https://github.com/ssb-ngi-pointer/ssb-network-errors/issues
- npm.io page: https://npm.io/package/ssb-network-errors

## Recent versions

- 1.0.1 (latest) — 2021-10-08
- 1.0.0 — 2021-06-18
- 0.4.0 — 2021-06-18
- 0.3.0 — 2021-06-18
- 0.2.0 — 2021-06-18
- 0.1.0 — 2021-06-18

## README

<!--
SPDX-FileCopyrightText: 2021 Andre Staltz

SPDX-License-Identifier: CC0-1.0
-->

# 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

```js
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

---
_Source: https://npm.io/package/ssb-network-errors · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
