From d19e269decaf1b72c7b255a9cf59f308d63acc9c Mon Sep 17 00:00:00 2001 From: Harrison Healey Date: Thu, 8 Nov 2018 12:15:07 -0500 Subject: [PATCH] MM-11477 Wrap objects thrown by Client4 in a proper error type (#2328) * MM-11477 Wrap objects thrown by Client4 in a proper error type * Update mattermost-redux --- app/fetch_preconfig.js | 17 +++++++++-------- package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/app/fetch_preconfig.js b/app/fetch_preconfig.js index 276c94d0f..c2d905540 100644 --- a/app/fetch_preconfig.js +++ b/app/fetch_preconfig.js @@ -6,6 +6,7 @@ import RNFetchBlob from 'rn-fetch-blob'; import urlParse from 'url-parse'; import {Client4} from 'mattermost-redux/client'; +import {ClientError} from 'mattermost-redux/client/client4'; import mattermostBucket from 'app/mattermost_bucket'; import LocalConfig from 'assets/config'; @@ -28,10 +29,10 @@ const handleRedirectProtocol = (url, response) => { Client4.doFetchWithResponse = async (url, options) => { if (!Client4.online) { - throw { + throw new ClientError(this.getUrl(), { message: 'no internet connection', url, - }; + }); } let response; @@ -48,21 +49,21 @@ Client4.doFetchWithResponse = async (url, options) => { data = await response.json(); } catch (err) { if (response && response.resp && response.resp.data && response.resp.data.includes('SSL certificate')) { - throw { + throw new ClientError(this.getUrl(), { message: 'You need to use a valid client certificate in order to connect to this Mattermost server', status_code: 401, url, - }; + }); } - throw { + throw new ClientError(this.getUrl(), { message: 'Received invalid response from the server.', intl: { id: t('mobile.request.invalid_response'), defaultMessage: 'Received invalid response from the server.', }, url, - }; + }); } if (headers[HEADER_X_CLUSTER_ID] || headers[HEADER_X_CLUSTER_ID.toLowerCase()]) { @@ -96,12 +97,12 @@ Client4.doFetchWithResponse = async (url, options) => { console.error(msg); // eslint-disable-line no-console } - throw { + throw new ClientError(this.getUrl(), { message: msg, server_error_id: data.id, status_code: data.status_code, url, - }; + }); }; const initFetchConfig = async () => { diff --git a/package-lock.json b/package-lock.json index 27b644fa5..f2a0039a7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9797,8 +9797,8 @@ "integrity": "sha1-izqsWIuKZuSXXjzepn97sylgH6w=" }, "mattermost-redux": { - "version": "github:mattermost/mattermost-redux#22625f7eb47fdbc88292916cd7ff48d5a4e353cd", - "from": "github:mattermost/mattermost-redux#22625f7eb47fdbc88292916cd7ff48d5a4e353cd", + "version": "github:mattermost/mattermost-redux#e467e16551cfc70be83c531f0836df894b2bf65a", + "from": "github:mattermost/mattermost-redux#e467e16551cfc70be83c531f0836df894b2bf65a", "requires": { "deep-equal": "1.0.1", "eslint-plugin-header": "1.2.0", diff --git a/package.json b/package.json index 2a4d409d8..d2771db2d 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "intl": "1.2.5", "jail-monkey": "1.0.0", "jsc-android": "224109.1.0", - "mattermost-redux": "github:mattermost/mattermost-redux#22625f7eb47fdbc88292916cd7ff48d5a4e353cd", + "mattermost-redux": "github:mattermost/mattermost-redux#e467e16551cfc70be83c531f0836df894b2bf65a", "mime-db": "1.36.0", "moment-timezone": "0.5.21", "prop-types": "15.6.2",