From 7bf3d7b1e20fbc5d08e0fc656c63491181a0d1cf Mon Sep 17 00:00:00 2001 From: Jethro Nederhof Date: Tue, 16 Oct 2018 15:03:30 +1100 Subject: [PATCH] Better schema fetching error messages --- src/validator.ts | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/validator.ts b/src/validator.ts index 293e1e8..16e7600 100644 --- a/src/validator.ts +++ b/src/validator.ts @@ -95,7 +95,7 @@ export = { const [evendor, ename, eformat, eversion] = match.slice(1); - if (!(schema in status)) { + if (typeof status[schema] === 'undefined') { status[schema] = null; for (const repo of Array.from(repositories)) { @@ -110,10 +110,35 @@ export = { console.log('received schema does not match expected values:', `${evendor}:${vendor}, ${ename}:${name}, ${eformat}:${format}, ${eversion}:${version}, `); } } - }).catch(null); + }).catch((error) => { + if (error.message && status[schema] === null) { + status[schema] = 'error'; + } else if (error.message === '' && (status[schema] === null || status[schema] === 'error')) { + status[schema] = 'cors'; + } + }); } } - return {valid: false, errors: ['Could not find or access schema definition in any configured repositories.', 'Try adding your Iglu repository in the extension settings.', 'Make sure you have whitelisted your IP and enabled CORS for the repository.'], location: null}; + const errors = { + cors: [ + 'Schema could not be found in any configured repositores.', + 'At least one repository had CORS errors while requesting the schema.', + ], + default: [ + 'Could not find or access schema definition in any configured repositories.', + ], + error: [ + 'Schema could not be found in any configured repositories.', + 'Try adding your Iglu repository in the extension settings.', + 'Make sure you have whitelisted your IP address.', + ], + }; + + return { + errors: errors[status[schema] || 'default'] || [], + location: null, + valid: false, + }; }, };