added error handling
This commit is contained in:
@@ -109,7 +109,7 @@ function getPairs(callback){
|
||||
if(err) {
|
||||
// Handle error
|
||||
console.log(err);
|
||||
return null;
|
||||
callback(null, true);
|
||||
} else {
|
||||
const pairs = [];
|
||||
|
||||
@@ -126,7 +126,7 @@ function getPairs(callback){
|
||||
pairs.push({name1:name1,name2:name2});
|
||||
}
|
||||
}
|
||||
callback(pairs);
|
||||
callback(pairs,false);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -143,7 +143,7 @@ function getAvailableNames(callback){
|
||||
if(err) {
|
||||
// Handle error
|
||||
console.log(err);
|
||||
return null;
|
||||
callback(null, true);
|
||||
} else {
|
||||
const names = [];
|
||||
|
||||
@@ -159,7 +159,7 @@ function getAvailableNames(callback){
|
||||
}
|
||||
|
||||
}
|
||||
callback(names);
|
||||
callback(names,false);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -218,8 +218,18 @@ function count_pairs(row, col, cntr){
|
||||
}
|
||||
|
||||
function MakePairsV3(callback){
|
||||
executeAPI(getAvailableNames,function(names){
|
||||
executeAPI(getPairs, function(pairs){
|
||||
executeAPI(getAvailableNames,function(names,error){
|
||||
if (error){
|
||||
console.log("Error - could not load names");
|
||||
callback.send({pairs: null, left: null, error: true, error_message: 'Could not load names list'});
|
||||
return;
|
||||
}
|
||||
executeAPI(getPairs, function(pairs,error){
|
||||
if (error){
|
||||
console.log("Error - could not load pairs");
|
||||
callback.send({pairs: null, left: null, error: true, error_message: 'Could not load pairs list'});
|
||||
return;
|
||||
}
|
||||
max_pairs = Math.floor(names.length/2);
|
||||
matrix=[];
|
||||
|
||||
@@ -244,8 +254,6 @@ function MakePairsV3(callback){
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
tree = [];
|
||||
done=false;
|
||||
|
||||
@@ -289,9 +297,10 @@ function MakePairsV3(callback){
|
||||
|
||||
if (names.length === 0) names=null;
|
||||
pairsForSave = result_pairs;
|
||||
callback.send({pairs: result_pairs, left: names});
|
||||
callback.send({pairs: result_pairs, left: names, error:false});
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function SavePairs(callback){
|
||||
|
||||
@@ -21,7 +21,7 @@ class App extends Component {
|
||||
this.setState({waitingPairs:true, renderFinish:false, waitingSave:true});
|
||||
|
||||
fetch(url, {}).then(function(response) { return response.json(); }).then(function(data) {
|
||||
this.setState({pairs : data.pairs, left:data.left, renderPairsList:true, waitingPairs:false, waitingSave:false});
|
||||
this.setState({pairs : data.pairs, left:data.left, renderPairsList:!data.error, waitingPairs:false, waitingSave:false, error: data.error, error_message: data.error_message});
|
||||
}.bind(this));
|
||||
|
||||
|
||||
@@ -46,6 +46,12 @@ class App extends Component {
|
||||
<div className = "horizontalDiv">
|
||||
<button disabled={this.state.waitingPairs} onClick = {this.getPairsEventHandler}>Get pairs</button>
|
||||
</div>
|
||||
{
|
||||
this.state.error &&
|
||||
<div>
|
||||
<h2> Error - {this.state.error_message} </h2>
|
||||
</div>
|
||||
}
|
||||
{
|
||||
this.state.renderPairsList &&
|
||||
<div>
|
||||
|
||||
Reference in New Issue
Block a user