Skip to content
This repository was archived by the owner on Jun 26, 2023. It is now read-only.

Commit d98bb23

Browse files
authored
feat: add crypto transmission error (#17)
* feat: add crypto transmission error * docs: add error to crypto readme
1 parent 6cf3723 commit d98bb23

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/crypto/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ Common crypto errors come with the interface, and can be imported directly. All
8585
```js
8686
const {
8787
InvalidCryptoExchangeError,
88+
InvalidCryptoTransmissionError,
8889
UnexpectedPeerError
8990
} = require('libp2p-interfaces/src/crypto/errors')
9091

@@ -95,4 +96,5 @@ console.log(error.code === UnexpectedPeerError.code) // true
9596
### Error Types
9697

9798
- `InvalidCryptoExchangeError` - Should be thrown when a peer provides data that is insufficient to finish the crypto exchange.
99+
- `InvalidCryptoTransmissionError` - Should be thrown when an error occurs during encryption/decryption.
98100
- `UnexpectedPeerError` - Should be thrown when the expected peer id does not match the peer id determined via the crypto exchange.

src/crypto/errors.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,19 @@ class InvalidCryptoExchangeError extends Error {
2222
}
2323
}
2424

25+
class InvalidCryptoTransmissionError extends Error {
26+
constructor (message = 'Invalid crypto transmission') {
27+
super(message)
28+
this.code = InvalidCryptoTransmissionError.code
29+
}
30+
31+
static get code () {
32+
return 'ERR_INVALID_CRYPTO_TRANSMISSION'
33+
}
34+
}
35+
2536
module.exports = {
2637
UnexpectedPeerError,
27-
InvalidCryptoExchangeError
38+
InvalidCryptoExchangeError,
39+
InvalidCryptoTransmissionError
2840
}

0 commit comments

Comments
 (0)