Skip to content

Commit

Permalink
Better schema fetching error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
jethron committed Oct 16, 2018
1 parent ae82534 commit 7bf3d7b
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions src/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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,
};
},
};

0 comments on commit 7bf3d7b

Please sign in to comment.