From 48ac96cfc7c9c3328d7a18707f00a2fe1bc743a1 Mon Sep 17 00:00:00 2001 From: lain Date: Wed, 13 Mar 2019 12:41:39 +0100 Subject: [PATCH] afterStoreSetup: Handle 404 cases. --- src/boot/after_store.js | 48 ++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/src/boot/after_store.js b/src/boot/after_store.js index f9e14eb2..a51f895e 100644 --- a/src/boot/after_store.js +++ b/src/boot/after_store.js @@ -7,28 +7,32 @@ import App from '../App.vue' const getStatusnetConfig = async ({ store }) => { try { const res = await window.fetch('/api/statusnet/config.json') - const data = await res.json() - const { name, closed: registrationClosed, textlimit, uploadlimit, server, vapidPublicKey } = data.site + if (res.ok) { + const data = await res.json() + const { name, closed: registrationClosed, textlimit, uploadlimit, server, vapidPublicKey } = data.site - store.dispatch('setInstanceOption', { name: 'name', value: name }) - store.dispatch('setInstanceOption', { name: 'registrationOpen', value: (registrationClosed === '0') }) - store.dispatch('setInstanceOption', { name: 'textlimit', value: parseInt(textlimit) }) - store.dispatch('setInstanceOption', { name: 'server', value: server }) + store.dispatch('setInstanceOption', { name: 'name', value: name }) + store.dispatch('setInstanceOption', { name: 'registrationOpen', value: (registrationClosed === '0') }) + store.dispatch('setInstanceOption', { name: 'textlimit', value: parseInt(textlimit) }) + store.dispatch('setInstanceOption', { name: 'server', value: server }) - // TODO: default values for this stuff, added if to not make it break on - // my dev config out of the box. - if (uploadlimit) { - store.dispatch('setInstanceOption', { name: 'uploadlimit', value: parseInt(uploadlimit.uploadlimit) }) - store.dispatch('setInstanceOption', { name: 'avatarlimit', value: parseInt(uploadlimit.avatarlimit) }) - store.dispatch('setInstanceOption', { name: 'backgroundlimit', value: parseInt(uploadlimit.backgroundlimit) }) - store.dispatch('setInstanceOption', { name: 'bannerlimit', value: parseInt(uploadlimit.bannerlimit) }) + // TODO: default values for this stuff, added if to not make it break on + // my dev config out of the box. + if (uploadlimit) { + store.dispatch('setInstanceOption', { name: 'uploadlimit', value: parseInt(uploadlimit.uploadlimit) }) + store.dispatch('setInstanceOption', { name: 'avatarlimit', value: parseInt(uploadlimit.avatarlimit) }) + store.dispatch('setInstanceOption', { name: 'backgroundlimit', value: parseInt(uploadlimit.backgroundlimit) }) + store.dispatch('setInstanceOption', { name: 'bannerlimit', value: parseInt(uploadlimit.bannerlimit) }) + } + + if (vapidPublicKey) { + store.dispatch('setInstanceOption', { name: 'vapidPublicKey', value: vapidPublicKey }) + } + + return data.site.pleromafe + } else { + throw (res) } - - if (vapidPublicKey) { - store.dispatch('setInstanceOption', { name: 'vapidPublicKey', value: vapidPublicKey }) - } - - return data.site.pleromafe } catch (error) { console.error('Could not load statusnet config, potentially fatal') console.error(error) @@ -38,7 +42,11 @@ const getStatusnetConfig = async ({ store }) => { const getStaticConfig = async () => { try { const res = await window.fetch('/static/config.json') - return res.json() + if (res.ok) { + return res.json() + } else { + throw (res) + } } catch (error) { console.warn('Failed to load static/config.json, continuing without it.') console.warn(error)