|
Lines 533-538
Link Here
|
| 533 |
591: _( 'Could not process the request.' ) |
533 |
591: _( 'Could not process the request.' ) |
| 534 |
}, |
534 |
}, |
| 535 |
|
535 |
|
|
|
536 |
_parseStatus: function(stat) { |
| 537 |
if (typeof stat == 'number') { |
| 538 |
// easy -> stat is a number |
| 539 |
return stat; |
| 540 |
} |
| 541 |
if (typeof stat == 'string') { |
| 542 |
// stat is a string, i.e., it could be "400" or "400 Bad Request"... try to parse it |
| 543 |
try { |
| 544 |
return parseInt(stat, 10); |
| 545 |
} catch(error) { |
| 546 |
// parsing failed -> return 0 as fallback |
| 547 |
return 0; |
| 548 |
} |
| 549 |
} |
| 550 |
// return 0 as fallback |
| 551 |
return 0; |
| 552 |
}, |
| 553 |
|
| 536 |
parseError: function(error) { |
554 |
parseError: function(error) { |
| 537 |
var status = error.status !== undefined ? error.status : 500; |
555 |
var status = error.status !== undefined ? error.status : 500; |
| 538 |
var message = this._statusMessages[status] || this._statusMessages[500]; |
556 |
var message = this._statusMessages[status] || this._statusMessages[500]; |
|
Lines 549-555
Link Here
|
| 549 |
} |
567 |
} |
| 550 |
if (error.response.data) { |
568 |
if (error.response.data) { |
| 551 |
// the response contained a valid JSON object, which contents is already html escaped |
569 |
// the response contained a valid JSON object, which contents is already html escaped |
| 552 |
status = error.response.data.status && parseInt(error.response.data.status, 10) || status; |
570 |
status = error.response.data.status && this._parseStatus(error.response.data.status) || status; |
| 553 |
message = error.response.data.message || ''; |
571 |
message = error.response.data.message || ''; |
| 554 |
result = error.response.data.result || null; |
572 |
result = error.response.data.result || null; |
| 555 |
} else { |
573 |
} else { |
|
Lines 566-575
Link Here
|
| 566 |
result = error.data.result || null; |
584 |
result = error.data.result || null; |
| 567 |
} else if(error.text) { |
585 |
} else if(error.text) { |
| 568 |
message = r.test(error.text) ? r.exec(error.text)[1] : error.text; |
586 |
message = r.test(error.text) ? r.exec(error.text)[1] : error.text; |
|
|
587 |
} else if(error.message && error.status) { |
| 588 |
// Uploader: errors are returned as simple JSON object { status: "XXX ...", message: "..." } |
| 589 |
message = error.message; |
| 590 |
status = error.status; |
| 569 |
} |
591 |
} |
| 570 |
|
592 |
|
| 571 |
return { |
593 |
return { |
| 572 |
status: parseInt(status, 10), |
594 |
status: this._parseStatus(status), |
| 573 |
message: String(message).replace(/\n/g, '<br>'), |
595 |
message: String(message).replace(/\n/g, '<br>'), |
| 574 |
result: result |
596 |
result: result |
| 575 |
}; |
597 |
}; |