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

Commit

Permalink
feat: add crypto transmission error (#17)
Browse files Browse the repository at this point in the history
* feat: add crypto transmission error

* docs: add error to crypto readme
  • Loading branch information
jacobheun authored Dec 28, 2019
1 parent 6cf3723 commit d98bb23
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/crypto/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ Common crypto errors come with the interface, and can be imported directly. All
```js
const {
InvalidCryptoExchangeError,
InvalidCryptoTransmissionError,
UnexpectedPeerError
} = require('libp2p-interfaces/src/crypto/errors')

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

- `InvalidCryptoExchangeError` - Should be thrown when a peer provides data that is insufficient to finish the crypto exchange.
- `InvalidCryptoTransmissionError` - Should be thrown when an error occurs during encryption/decryption.
- `UnexpectedPeerError` - Should be thrown when the expected peer id does not match the peer id determined via the crypto exchange.
14 changes: 13 additions & 1 deletion src/crypto/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,19 @@ class InvalidCryptoExchangeError extends Error {
}
}

class InvalidCryptoTransmissionError extends Error {
constructor (message = 'Invalid crypto transmission') {
super(message)
this.code = InvalidCryptoTransmissionError.code
}

static get code () {
return 'ERR_INVALID_CRYPTO_TRANSMISSION'
}
}

module.exports = {
UnexpectedPeerError,
InvalidCryptoExchangeError
InvalidCryptoExchangeError,
InvalidCryptoTransmissionError
}

0 comments on commit d98bb23

Please sign in to comment.