Skip to content

Commit b7d4598

Browse files
author
Matthieu Napoli
committed
Simulate error cases 50% of the time to have a great demo
1 parent 739d3cd commit b7d4598

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

App/Containers/HomeScreen.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react'
2-
import { Platform, StyleSheet, Text, View } from 'react-native'
2+
import { Platform, StyleSheet, Text, View, Button } from 'react-native'
33
import { connect } from 'react-redux'
44
import { PropTypes } from 'prop-types'
55
import ExampleActions from 'App/Stores/Example/Actions'
@@ -24,6 +24,7 @@ class HomeScreen extends React.Component {
2424
The weather temperature is: {this.props.temperature}
2525
</Text>
2626
<Text style={styles.instructions}>{this.props.errorMessage}</Text>
27+
<Button onPress={this.props.fetchTemperature} title="Refresh"/>
2728
</View>
2829
)
2930
}

App/Service/WeatherService.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ const weatherApiClient = create({
1010
})
1111

1212
function fetchTemperature() {
13+
// Simulate an error 50% of the time just for testing purposes
14+
if (Math.random() > 0.5) {
15+
return new Promise(function(resolve, reject) {
16+
resolve(null);
17+
});
18+
}
19+
1320
const locationQuery = escape(
1421
"select item.condition.temp from weather.forecast where woeid in (select woeid from geo.places where text='Lyon, Rhone-Alpes, FR') and u='c'"
1522
)

0 commit comments

Comments
 (0)