Skip to content

Commit

Permalink
Merge pull request #10 from Vadimator/master
Browse files Browse the repository at this point in the history
fixed ajax promise
  • Loading branch information
vitalyiegorov authored Aug 26, 2016
2 parents dd098ce + 2a623d5 commit 9a72019
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,19 @@ SamsonJS.extend({

xhr.onload = function () {
if (this.status == 200) {
var response = this.response;

// Convert response to JSON object
try {
var response = JSON.parse(this.response);

if (response && response.status !== 0) {
resolve(response);
} else { // Call reject with response object
throw new Error(response);
}
response = JSON.parse(response);
} catch (e) {
throw new Error('JSON response parsing:' + e);
throw 'JSON response parsing:' + e.toString();
}

if (response && response.status !== 0) {
resolve(response);
} else { // Call reject with response object
reject(response);
}
} else {
var error = new Error(this.statusText);
Expand Down

0 comments on commit 9a72019

Please sign in to comment.