(action, option, xhr)
| 1 | function getError(action, option, xhr) { |
| 2 | let msg; |
| 3 | if (xhr.response) { |
| 4 | msg = `${xhr.status} ${xhr.response.error || xhr.response}`; |
| 5 | } else if (xhr.responseText) { |
| 6 | msg = `${xhr.status} ${xhr.responseText}`; |
| 7 | } else { |
| 8 | msg = `fail to post ${action} ${xhr.status}`; |
| 9 | } |
| 10 | |
| 11 | const err = new Error(msg); |
| 12 | err.status = xhr.status; |
| 13 | err.method = 'post'; |
| 14 | err.url = action; |
| 15 | return err; |
| 16 | } |
| 17 | |
| 18 | function getBody(xhr) { |
| 19 | const text = xhr.responseText || xhr.response; |