https://github.com/ssbc/ssb-network-errors
Classify muxrpc and SSB network errors by severity
https://github.com/ssbc/ssb-network-errors
Last synced: 11 months ago
JSON representation
Classify muxrpc and SSB network errors by severity
- Host: GitHub
- URL: https://github.com/ssbc/ssb-network-errors
- Owner: ssbc
- Created: 2021-06-18T15:31:04.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2021-10-08T11:05:47.000Z (over 4 years ago)
- Last Synced: 2025-07-30T15:21:56.670Z (11 months ago)
- Language: JavaScript
- Homepage:
- Size: 18.6 KB
- Stars: 4
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSES/CC0-1.0.txt
Awesome Lists containing this project
README
# 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