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

Commit

Permalink
feat: crypto errors (#4)
Browse files Browse the repository at this point in the history
* chore: ignore docs folder

* feat: add invalid crypto exchange error
  • Loading branch information
jacobheun authored Oct 29, 2019
1 parent bcb52ae commit d2fe2d1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

build
dist
docs

# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
Expand Down
4 changes: 3 additions & 1 deletion src/crypto/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ Common crypto errors come with the interface, and can be imported directly. All

```js
const {
InvalidCryptoExchangeError,
UnexpectedPeerError
} = require('libp2p-interfaces/src/crypto/errors')

Expand All @@ -93,4 +94,5 @@ console.log(error.code === UnexpectedPeerError.code) // true

### Error Types

- `UnexpectedPeerError` - Should be thrown when the expected peer id does not match the peer id determined via the crypto exchange
- `InvalidCryptoExchangeError` - Should be thrown when a peer provides data that is insufficient to finish the crypto exchange.
- `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 @@ -11,6 +11,18 @@ class UnexpectedPeerError extends Error {
}
}

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

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

module.exports = {
UnexpectedPeerError
UnexpectedPeerError,
InvalidCryptoExchangeError
}

0 comments on commit d2fe2d1

Please sign in to comment.