From 4cbf03cb5ad0981606682a2b23dbcfcfb18e4e52 Mon Sep 17 00:00:00 2001 From: Vijay A Date: Sat, 21 Aug 2021 21:58:58 +0530 Subject: refactor: fail quickly if the initialization data is incorrect --- src/models/Recipe.ts | 8 ++------ src/models/Service.js | 8 +++----- 2 files changed, 5 insertions(+), 11 deletions(-) (limited to 'src/models') diff --git a/src/models/Recipe.ts b/src/models/Recipe.ts index 33d383983..0a93fbc5a 100644 --- a/src/models/Recipe.ts +++ b/src/models/Recipe.ts @@ -76,12 +76,8 @@ export default class Recipe { throw Error(`Recipe '${data.name}' requires Id`); } - try { - if (!semver.valid(data.version)) { - throw Error(`Version ${data.version} of recipe '${data.name}' is not a valid semver version`); - } - } catch (e) { - console.warn(e.message); + if (!semver.valid(data.version)) { + throw Error(`Version ${data.version} of recipe '${data.name}' is not a valid semver version`); } this.id = data.id || this.id; diff --git a/src/models/Service.js b/src/models/Service.js index c2b081864..4b78b9a40 100644 --- a/src/models/Service.js +++ b/src/models/Service.js @@ -14,7 +14,7 @@ const debug = require('debug')('Ferdi:Service'); export default class Service { id = ''; - recipe = ''; + recipe = null; _webview = null; @@ -94,13 +94,11 @@ export default class Service { constructor(data, recipe) { if (!data) { - console.error('Service config not valid'); - return null; + throw Error('Service config not valid'); } if (!recipe) { - console.error('Service recipe not valid'); - return null; + throw Error('Service recipe not valid'); } this.userAgentModel = new UserAgent(recipe.overrideUserAgent); -- cgit v1.2.3-54-g00ecf