CRITICAL
Rule Definition
Ensure that each web service callback is going to be properly checked in order to make sure you will not miss any problem that occurred in your application and you will give the information to the user.
Remediation
Always implement success, error, complete callbacks before jQuery 3.0
Always implement done, fail, always callbacks with jQuery 3.0 (and latest)
Violation Code Sample
// error callback is missing
$.ajax({
type: 'POST',
url: '_auth/login',
success: function(res, status, xhr) { window.location.reload(); },
complete: function(xhr, status, err) {
}
});
-------------------------------------------
// fail callback is missing
$.ajax({
type: 'POST',
url: '_auth/login'
})
.done(successHandler)
.always();
Fixed Code Sample
$.ajax({
type: 'POST',
url: '_auth/login',
success: function(res, status, xhr) { window.location.reload(); },
error: function(res, status, xhr) { window.location.reload(); },
complete: function(xhr, status, err) {
}
});
-------------------------------------------
$.ajax({
type: 'POST',
url: '_auth/login'
})
.done(successHandler)
.fail(errorHandler)
.always();
Reference
https://api.jquery.com/jquery.ajax/
Related Technologies
Technical Criterion
CWE-392 - Missing Report of Error Condition
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.