feat(extra-info): add method to handle info retrieval error
BaseExtraInfoInjection now has a new overridable method
injectOnInfoRetrievalError which is called when an error ocurred while
trying to obtain the current information. This will be used in the
future to inject an error message/chip.
Bug: twpowertools:93
Change-Id: I64f3784a28db3976fdfb6e4e66949d842c4ff4fa
diff --git a/src/contentScripts/communityConsole/extraInfo/injections/base.js b/src/contentScripts/communityConsole/extraInfo/injections/base.js
index 1498efd..ee997c4 100644
--- a/src/contentScripts/communityConsole/extraInfo/injections/base.js
+++ b/src/contentScripts/communityConsole/extraInfo/injections/base.js
@@ -21,6 +21,13 @@
shouldImplement('inject');
}
+ /**
+ * Overridable method which is called when an error ocurred while retrieving
+ * the info needed to inject the extra information. This is useful to show an
+ * error component in the screen.
+ */
+ injectOnInfoRetrievalError() {}
+
async isEnabled() {
return await this.optionsWatcher.isEnabled('extrainfo');
}
@@ -33,6 +40,10 @@
if (!isEnabled) return;
return this.infoHandler.getCurrentInfo(injectionDetails)
+ .catch(err => {
+ this.injectOnInfoRetrievalError();
+ throw err;
+ })
.then(info => this.inject(info, injectionDetails))
.catch(err => {
console.error(