From 7d7615295488eadbf92f5967004062be5a5a6ac2 Mon Sep 17 00:00:00 2001 From: Marvel-Dreamer <22347282+Marvel-Dreamer@users.noreply.github.com> Date: Fri, 21 Aug 2020 19:38:25 +0800 Subject: [PATCH] Feat/intl report hook (#139) * feat: Add hooks before get and getHTML methods to execute custom methods * feat: Add fault tolerance to hook functions --- src/ReactIntlUniversal.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/ReactIntlUniversal.js b/src/ReactIntlUniversal.js index 5a17a48..6cdf18e 100644 --- a/src/ReactIntlUniversal.js +++ b/src/ReactIntlUniversal.js @@ -33,7 +33,11 @@ class ReactIntlUniversal { */ get(key, variables) { if (this.options.intlGetHook) { - this.options.intlGetHook(key, this.options.currentLocale); + try { + this.options.intlGetHook(key, this.options.currentLocale); + } catch (e) { + console.log('intl get hook error: ', e); + } } invariant(key, "key is required"); const { locales, currentLocale, formats } = this.options; @@ -98,7 +102,11 @@ class ReactIntlUniversal { */ getHTML(key, variables) { if (this.options.intlGetHook) { - this.options.intlGetHook(key, this.options.currentLocale); + try { + this.options.intlGetHook(key, this.options.currentLocale); + } catch (e) { + console.log('intl get hook error: ', e); + } } let msg = this.get(key, variables); if (msg) {