mattermost-mobile/app/components/error_text.js
Chris Duarte 80edba14da PLT-5608 App crashes when invalid server url is selected (#285)
* PLT-5608 App crashes with wrong URL

* Review feedback

* FormattedError Modification

* Rename i18n id for server ping failure message

* Display friendly error message if server ping fails w/o response
2017-02-24 21:36:49 -03:00

42 lines
1.1 KiB
JavaScript

// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import React, {PropTypes, PureComponent} from 'react';
import {Text} from 'react-native';
import FormattedText from 'app/components/formatted_text';
import {GlobalStyles} from 'app/styles';
export default class ErrorText extends PureComponent {
static propTypes = {
error: PropTypes.oneOfType([PropTypes.string, PropTypes.object])
};
static defaultProps = {
error: {}
};
render() {
if (!this.props.error) {
return null;
}
if (this.props.error.hasOwnProperty('intl')) {
const {intl} = this.props.error;
return (
<FormattedText
id={intl.id}
defaultMessage={intl.defaultMessage}
values={intl.values}
style={GlobalStyles.errorLabel}
/>
);
}
return (
<Text style={GlobalStyles.errorLabel}>
{this.props.error.message || this.props.error}
</Text>
);
}
}