From 2435560c95cad32aaefa096fd4cfe52f9f51ec14 Mon Sep 17 00:00:00 2001 From: Tyler Yasaka Date: Tue, 13 Nov 2018 09:52:16 -0800 Subject: [PATCH] Move some validation to `determineAddress` --- src/OrbitDB.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/OrbitDB.js b/src/OrbitDB.js index e20bb5d..7b196c7 100644 --- a/src/OrbitDB.js +++ b/src/OrbitDB.js @@ -216,16 +216,10 @@ class OrbitDB { async create (name, type, options = {}) { logger.debug(`create()`) - if (!OrbitDB.isValidType(type)) - throw new Error(`Invalid database type '${type}'`) - // The directory to look databases from can be passed in as an option const directory = options.directory || this.directory logger.debug(`Creating database '${name}' as ${type} in '${directory}'`) - if (OrbitDBAddress.isValid(name)) - throw new Error(`Given database name is an address. Please give only the name of the database!`) - // Create the database address const dbAddress = await this.determineAddress(name, type, options) @@ -248,6 +242,12 @@ class OrbitDB { } async determineAddress(name, type, options = {}) { + if (!OrbitDB.isValidType(type)) + throw new Error(`Invalid database type '${type}'`) + + if (OrbitDBAddress.isValid(name)) + throw new Error(`Given database name is an address. Please give only the name of the database!`) + // Create an AccessController const accessController = new AccessController(this._ipfs) /* Disabled temporarily until we do something with the admin keys */