S
Stor Ursa
I'm looking for a good way of handling errors after an asynchronous
call.
Currently I have a model view controller set up in javascript.
the view is the DOM
the Controller manipulates the DOM / Handle Events Fire From the DOM
the Model performs processing requests and responses from the back
end, and maintains state variables, like current search page.
I'm looking for a good way of reporting errors that come from the back
end, while maintaining the MVC. The outline of my code below is the
best way I can think of right now.
Can you guys suggest anything better?
Sample Code.
Model.prototype.search = function() {
try {
this.controller.gatherSearchParams();
} catch(error) {
this.controller.reportError(error.description);
}
this.sendRequest(this.url, this.params, this.searchCompleted);
};
Model.prototype.searchComplete = function(response) {
if(this.ResponseHelper.containsError(response)) {
this.controller.reportError(this.ResponseHelper.getErrorMsg
(response));
}
};
call.
Currently I have a model view controller set up in javascript.
the view is the DOM
the Controller manipulates the DOM / Handle Events Fire From the DOM
the Model performs processing requests and responses from the back
end, and maintains state variables, like current search page.
I'm looking for a good way of reporting errors that come from the back
end, while maintaining the MVC. The outline of my code below is the
best way I can think of right now.
Can you guys suggest anything better?
Sample Code.
Model.prototype.search = function() {
try {
this.controller.gatherSearchParams();
} catch(error) {
this.controller.reportError(error.description);
}
this.sendRequest(this.url, this.params, this.searchCompleted);
};
Model.prototype.searchComplete = function(response) {
if(this.ResponseHelper.containsError(response)) {
this.controller.reportError(this.ResponseHelper.getErrorMsg
(response));
}
};