summaryrefslogtreecommitdiff
path: root/resources/js/db.js
diff options
context:
space:
mode:
Diffstat (limited to 'resources/js/db.js')
-rw-r--r--resources/js/db.js39
1 files changed, 27 insertions, 12 deletions
diff --git a/resources/js/db.js b/resources/js/db.js
index a04d32e..54fc751 100644
--- a/resources/js/db.js
+++ b/resources/js/db.js
@@ -76,20 +76,35 @@ const DB = {
};
async function initializeDB () {
- DB.allMonsters = await fetch('/db/_generated/all-monsters.json').then((response) => response.json());
- DB.allAnimations = await fetch('/db/_generated/animations.json').then((response) => response.json());
- DB.allItems = await fetch('/db/_generated/all-items.json').then((response) => response.json());
+ DB.allMonsters = await fetchDBData('/db/_generated/all-monsters.json').then((response) => response.json());
+ DB.allAnimations = await fetchDBData('/db/_generated/animations.json').then((response) => response.json());
+ DB.allItems = await fetchDBData('/db/_generated/all-items.json').then((response) => response.json());
- DB.shapes = await fetch('/modules/tuxemon/mods/tuxemon/db/shape/shapes.json').then((response) => response.json());
+ DB.shapes = await fetchDBData('/modules/tuxemon/mods/tuxemon/db/shape/shapes.json').then((response) => response.json());
for (const element of Object.keys(ElementType)) {
- DB.elements[element] = await fetch(`/modules/tuxemon/mods/tuxemon/db/element/${element}.json`).then((response) => response.json());
+ DB.elements[element] = await fetchDBData(`/modules/tuxemon/mods/tuxemon/db/element/${element}.json`).then((response) => response.json());
}
await fetchTranslation(Memory.state.Settings.language);
applyTranslation();
- DB.currencies = await fetch('/db/_generated/currencies.json').then((response) => response.json());
+ DB.currencies = await fetchDBData('/db/_generated/currencies.json').then((response) => response.json());
+}
+
+/**
+ * @param arguments
+ *
+ * @returns {Promise<Response>}
+ */
+async function fetchDBData (...arguments) {
+ const response = await fetch(...arguments);
+
+ if (!response.ok) {
+ throw new Error(`"${response.url}": ${response.statusText}`);
+ }
+
+ return response;
}
/**
@@ -99,7 +114,7 @@ async function initializeDB () {
*/
async function fetchMonster (slug) {
if (! DB.monsters[slug]) {
- DB.monsters[slug] = await fetch(`/modules/tuxemon/mods/tuxemon/db/monster/${slug}.json`).then((response) => response.json());
+ DB.monsters[slug] = await fetchDBData(`/modules/tuxemon/mods/tuxemon/db/monster/${slug}.json`).then((response) => response.json());
}
const monster = new Monster(slug);
@@ -115,7 +130,7 @@ async function fetchMonster (slug) {
*/
async function fetchTechnique (slug) {
if (! DB.techniques[slug]) {
- DB.techniques[slug] = await fetch(`/modules/tuxemon/mods/tuxemon/db/technique/${slug}.json`).then((response) => response.json());
+ DB.techniques[slug] = await fetchDBData(`/modules/tuxemon/mods/tuxemon/db/technique/${slug}.json`).then((response) => response.json());
}
return new Technique(slug);
@@ -128,7 +143,7 @@ async function fetchTechnique (slug) {
*/
async function fetchStatusEffect (slug) {
if (! DB.statusEffects[slug]) {
- DB.statusEffects[slug] = await fetch(`/modules/tuxemon/mods/tuxemon/db/technique/status_${slug}.json`).then((response) => response.json());
+ DB.statusEffects[slug] = await fetchDBData(`/modules/tuxemon/mods/tuxemon/db/technique/status_${slug}.json`).then((response) => response.json());
}
return new StatusEffect(slug);
@@ -141,7 +156,7 @@ async function fetchStatusEffect (slug) {
*/
async function fetchItem (slug) {
if (! DB.items[slug]) {
- DB.items[slug] = await fetch(`/modules/tuxemon/mods/tuxemon/db/item/${slug}.json`).then((response) => response.json());
+ DB.items[slug] = await fetchDBData(`/modules/tuxemon/mods/tuxemon/db/item/${slug}.json`).then((response) => response.json());
}
return new Item(slug);
@@ -154,7 +169,7 @@ async function fetchItem (slug) {
*/
async function fetchTranslation (locale) {
if (! DB.translations[locale]) {
- DB.translations[locale] = await fetch(`/db/_generated/i18n/${locale}.json`).then((response) => response.json());
+ DB.translations[locale] = await fetchDBData(`/db/_generated/i18n/${locale}.json`).then((response) => response.json());
}
return DB.translations[locale];
@@ -171,7 +186,7 @@ async function fetchArea (slug) {
}
if (! DB.areas[slug]) {
- DB.areas[slug] = await fetch(`/db/_generated/areas/${slug}.json`).then((response) => response.json());
+ DB.areas[slug] = await fetchDBData(`/db/_generated/areas/${slug}.json`).then((response) => response.json());
}
const area = new Area(slug);