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
This commit is contained in:
Harrison Healey 2018-11-08 12:15:07 -05:00
parent bbd65b292f
commit d19e269dec
3 changed files with 12 additions and 11 deletions

View file

@ -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 () => {

4
package-lock.json generated
View file

@ -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",

View file

@ -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",