DictionaryImporter improvements (#1862)

* Improve error message

* Simplify URL for JSON fetching
This commit is contained in:
toasted-nutbread 2021-07-31 14:00:19 -04:00 committed by GitHub
parent 454ffaad96
commit 11f210375e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -434,15 +434,13 @@ class DictionaryImporter {
async _getImageMedia(context, path, entry) { async _getImageMedia(context, path, entry) {
const {media} = context; const {media} = context;
const {dictionary, reading} = entry; const {dictionary} = entry;
let errorSource = entry.expression; const createError = (message) => {
if (reading.length > 0) { const {expression, reading} = entry;
errorSource += ` (${reading})`; const readingSource = reading.length > 0 ? ` (${reading})`: '';
} return new Error(`${message} at path ${JSON.stringify(path)} for ${expression}${readingSource} in ${dictionary}`);
errorSource += dictionary; };
const createError = (message) => new Error(`${message} at path ${JSON.stringify(path)} for ${errorSource}`);
// Check if already added // Check if already added
let mediaData = media.get(path); let mediaData = media.get(path);
@ -490,7 +488,7 @@ class DictionaryImporter {
} }
async _fetchJsonAsset(url) { async _fetchJsonAsset(url) {
const response = await fetch(chrome.runtime.getURL(url), { const response = await fetch(url, {
method: 'GET', method: 'GET',
mode: 'no-cors', mode: 'no-cors',
cache: 'default', cache: 'default',