diff --git a/src/components/Farmhand/Farmhand.js b/src/components/Farmhand/Farmhand.js index b1b5aa252..0ddc5c129 100644 --- a/src/components/Farmhand/Farmhand.js +++ b/src/components/Farmhand/Farmhand.js @@ -939,15 +939,20 @@ export default class Farmhand extends FarmhandReducers { this.showNotification(CONNECTED_TO_ROOM`${room}`, 'success') } catch (e) { - const message = e instanceof Error ? e.message : 'Unexpected error' - // TODO: Add some reasonable fallback behavior in case the server request // fails. Possibility: Regenerate valueAdjustments and notify the user // they are offline. - this.showNotification(`Server error: ${message}`, 'error') + this.showNotification(SERVER_ERROR, 'error') console.error(e) + + this.setState(() => { + return { + redirect: '/', + cowIdOfferedForTrade: '', + } + }) } this.setState({ @@ -1064,11 +1069,17 @@ export default class Farmhand extends FarmhandReducers { nextDayState.priceSurges ) } catch (e) { + // NOTE: This will get reached when there's an issue posting data to the server. serverMessages.push({ message: SERVER_ERROR, severity: 'error', }) + this.setState({ + redirect: '/', + cowIdOfferedForTrade: '', + }) + console.error(e) } diff --git a/src/strings.js b/src/strings.js index 06598fb5b..c335567d3 100644 --- a/src/strings.js +++ b/src/strings.js @@ -14,7 +14,7 @@ export const INVALID_DATA_PROVIDED = 'Invalid Farmhand data provided.' export const UPDATE_AVAILABLE = "A game update is available! Click this message to reload and see what's new." export const SERVER_ERROR = - "There was an issue communicating with the server. You can keep playing offline, and you'll be reconnected as soon as things improve." + 'There was an issue connecting to the server. Please try again in a moment.' export const CONNECTING_TO_SERVER = 'Connecting...' export const DISCONNECTING_FROM_SERVER = 'Disconnecting...' export const DISCONNECTED_FROM_SERVER = 'You are now playing offline.'