From 974e4d362fabdcfac18fb535ed96996a003dc986 Mon Sep 17 00:00:00 2001 From: Xiao Gui <xgui3783@gmail.com> Date: Wed, 24 Nov 2021 16:00:18 +0100 Subject: [PATCH] chore: allow snackbar to be dismissed chore: show more in depth error when gitlab snippet store is not defined --- deploy/saneUrl/index.js | 7 ++++++- deploy/saneUrl/util.js | 2 ++ src/plugin/pluginBanner/pluginBanner.component.ts | 8 ++++++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/deploy/saneUrl/index.js b/deploy/saneUrl/index.js index 72d0f9f9e..010f28e87 100644 --- a/deploy/saneUrl/index.js +++ b/deploy/saneUrl/index.js @@ -7,7 +7,12 @@ const RedisStore = require('rate-limit-redis') const { redisURL } = require('../lruStore') const { ProxyStore, NotExactlyPromiseAny } = require('./util') -const store = new Store() +let store +try { + store = new Store() +} catch (e) { + console.error(`Failed to new store.`, e) +} const depStore = new DepcStore() const proxyStore = new ProxyStore(store) diff --git a/deploy/saneUrl/util.js b/deploy/saneUrl/util.js index 949025cdc..12fce0a38 100644 --- a/deploy/saneUrl/util.js +++ b/deploy/saneUrl/util.js @@ -2,6 +2,7 @@ const { NotFoundError } = require('./store') class ProxyStore { static async StaticGet(store, req, name) { + if (!store) throw new Error(`store is falsy`) const payload = JSON.parse(await store.get(name)) const { expiry, value, ...rest } = payload if (expiry && (Date.now() > expiry)) { @@ -21,6 +22,7 @@ class ProxyStore { } async set(req, name, value) { + if (!this.store) throw new Error(`store is falsy`) const supplementary = req.user ? { userId: req.user.id, diff --git a/src/plugin/pluginBanner/pluginBanner.component.ts b/src/plugin/pluginBanner/pluginBanner.component.ts index 069be28e6..689f0aa32 100644 --- a/src/plugin/pluginBanner/pluginBanner.component.ts +++ b/src/plugin/pluginBanner/pluginBanner.component.ts @@ -53,10 +53,14 @@ export class PluginBannerUI { try { await this.pluginServices.addPluginViaManifestUrl(manifestUrl) this.loadingThirdpartyPlugin = false - this.matSnackbar.open(`Adding plugin successful`) + this.matSnackbar.open(`Adding plugin successful`, 'Dismiss', { + duration: 5000 + }) } catch (e) { this.loadingThirdpartyPlugin = false - this.matSnackbar.open(`Error adding plugin: ${e.toString()}`) + this.matSnackbar.open(`Error adding plugin: ${e.toString()}`, 'Dismiss', { + duration: 5000 + }) } } } -- GitLab