Skip to content

Commit f6b7976

Browse files
committed
#2401: ajax_caller.js, define custom error throwing logic
1 parent b432d62 commit f6b7976

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/js/ajax_caller.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,20 @@ function ajaxCaller(callbackDone, callbackFail, args) {
2828
// asynchronous callback
2929
callbackDone(response.json());
3030
} else {
31-
// need status in variables
32-
var errorCode = response.status;
33-
34-
// define error
35-
var error = new Error(
31+
// variables
32+
var error = {
3633
response.statusText,
34+
response.status,
3735
response.headers
38-
);
39-
error.response = response;
36+
}
37+
38+
// throw error
4039
throw error;
4140
}
42-
}).catch(function(errorMessage, headers) {
41+
}).catch(function(e) {
4342
// variables
44-
var serverResponse = (headers) ? headers : 'no server response';
43+
var serverResponse = (e.headers) ? e.headers : 'no server response';
4544
// asynchronous callback
46-
callbackFail(errorMessage, serverResponse);
45+
callbackFail(e.statusText, e.status);
4746
});
4847
}

0 commit comments

Comments
 (0)