From d2fe2d1b3609b1a1751ea432c7aebb1e3dd044a5 Mon Sep 17 00:00:00 2001 From: Jacob Heun Date: Tue, 29 Oct 2019 12:12:09 +0100 Subject: [PATCH] feat: crypto errors (#4) * chore: ignore docs folder * feat: add invalid crypto exchange error --- .gitignore | 1 + src/crypto/README.md | 4 +++- src/crypto/errors.js | 16 ++++++++++++++-- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index fad1fce..2bf84b1 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/src/crypto/README.md b/src/crypto/README.md index 7d15a5e..ac00951 100644 --- a/src/crypto/README.md +++ b/src/crypto/README.md @@ -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') @@ -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. diff --git a/src/crypto/errors.js b/src/crypto/errors.js index 3784482..dc6af46 100644 --- a/src/crypto/errors.js +++ b/src/crypto/errors.js @@ -11,6 +11,18 @@ class UnexpectedPeerError extends Error { } } -module.exports = { - UnexpectedPeerError +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, + InvalidCryptoExchangeError }