From 8d9cbe6698da468884697885f364ac8c97986dcc Mon Sep 17 00:00:00 2001 From: Alexander Cerutti Date: Sat, 1 Jun 2019 00:48:32 +0200 Subject: [PATCH] Delegated model checks to getModelContents function; Added try-catch to handle failure --- src/factory.ts | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/src/factory.ts b/src/factory.ts index 1264e02..4d6f54a 100644 --- a/src/factory.ts +++ b/src/factory.ts @@ -41,25 +41,14 @@ async function createPass(options: FactoryOptions) { // Voglio leggere i certificati // Voglio leggere il model (se non è un oggetto) - /* Model checks */ - - if (!options.model) { - throw new Error("Unable to create Pass: no model passed"); - } - - if (typeof options.model !== "string" && typeof options.model !== "object") { - throw new Error("Unable to create Pass: unsupported type"); - } - - if (typeof options.model === "object" && !Object.keys(options.model).length) { - throw new Error("Unable to create Pass: object model has no content"); - } - - /* Certificates checks */ - - const { certificates } = await Promise.all([ + try { + const [model, certificates] = await Promise.all([ + getModelContents(options.model), readCertificatesFromOptions(options.certificates) ]); + } catch (err) { + // @TODO: analyze the error and stop the execution somehow + } // Controllo se il model è un oggetto o una stringa // Se è un oggetto passo avanti