Skip to content

Commit 1e99191

Browse files
committed
ADding error handling for failed submissions
1 parent 567484a commit 1e99191

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

src/js/action/openAssessments.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const allAssessments = function (state, action, beans) {
2222

2323
const syncAssessment = function (state, action, beans) {
2424
const assessmentSyncService = beans.get(AssessmentSyncService);
25-
assessmentSyncService.syncFacilityAssessment(action.assessment, action.cb);
25+
assessmentSyncService.syncFacilityAssessment(action.assessment, action.cb, action.errorHandler);
2626
return Object.assign(state, {syncing: [action.assessment.uuid].concat(state.syncing)});
2727
};
2828

src/js/service/AssessmentSyncService.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class AssessmentSyncService extends BaseService {
2727
this.serverURL = this.getService(SettingsService).getServerURL();
2828
}
2929

30-
syncChecklists(originalAssessment, cb) {
30+
syncChecklists(originalAssessment, cb, errorHandler) {
3131
return (facilityAssessment) => {
3232
const checklistService = this.getService(ChecklistService);
3333
const facilityAssessmentService = this.getService(FacilityAssessmentService);
@@ -58,16 +58,16 @@ class AssessmentSyncService extends BaseService {
5858
},
5959
(error) => {
6060
Logger.logError('AssessmentSyncService', JSON.stringify(error));
61-
cb();
61+
errorHandler();
6262
});
6363
}
6464
}
6565

66-
syncFacilityAssessment(assessment, cb) {
66+
syncFacilityAssessment(assessment, cb, errorHandler) {
6767
this.serverURL = this.getService(SettingsService).getServerURL();
6868
let facilityAssessmentDTO = facilityAssessmentMapper(assessment);
6969
post(`${this.serverURL}/api/facility-assessment`, facilityAssessmentDTO,
70-
this.syncChecklists(assessment, cb), cb);
70+
this.syncChecklists(assessment, cb, errorHandler), errorHandler);
7171
}
7272
}
7373

src/js/views/dashboard/open/OpenView.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, {Component} from 'react';
2-
import {Text, StyleSheet, View, ScrollView} from 'react-native';
2+
import {View, Alert} from 'react-native';
33
import AbstractComponent from "../../common/AbstractComponent";
44
import Actions from '../../../action';
55
import Dashboard from '../Dashboard';
@@ -47,9 +47,22 @@ class OpenView extends AbstractComponent {
4747
handleSubmit(assessment) {
4848
return () => this.dispatchAction(Actions.SYNC_ASSESSMENT, {
4949
"assessment": assessment,
50-
cb: () => this.dispatchAction(Actions.ASSESSMENT_SYNCED, {assessment: assessment, ...this.props})
50+
cb: () => this.dispatchAction(Actions.ASSESSMENT_SYNCED, {assessment: assessment, ...this.props}),
51+
errorHandler: () => this.submissionError(assessment)
5152
});
53+
}
5254

55+
submissionError(assessment) {
56+
Alert.alert(
57+
'Submission Error',
58+
"An error occured submitting the assessment. Please check connectivity to the server.",
59+
[
60+
{
61+
text: 'Ok',
62+
onPress: () => this.dispatchAction(Actions.ASSESSMENT_SYNCED, {assessment: assessment, ...this.props})
63+
}
64+
]
65+
)
5366
}
5467

5568
allowSubmit() {

0 commit comments

Comments
 (0)