Skip to content

Commit

Permalink
Include request/response info with Abort error
Browse files Browse the repository at this point in the history
  • Loading branch information
Bill Heaton committed Sep 14, 2018
1 parent e17365a commit 5e8183f
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion addon/adapters/rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -1228,7 +1228,8 @@ function ajaxError(adapter, payload, requestData, responseData) {
} else if (responseData.textStatus === 'timeout') {
error = new TimeoutError();
} else if (responseData.textStatus === 'abort' || responseData.status === 0) {
error = new AbortError();
// TODO REVIEW should we use an adapter method for this, e.g. like handleResponse?
error = handleAbort(requestData, responseData);
} else {
try {
error = adapter.handleResponse(
Expand All @@ -1245,6 +1246,14 @@ function ajaxError(adapter, payload, requestData, responseData) {
return error;
}

// Adapter abort error to include any relevent info, e.g. request/response:
// 'The adapter operation was aborted'
function handleAbort(requestData, responseData) {
let msg = `Request failed: ${requestData.method} ${requestData.url} ${requestData.errorThrown || ''}`;
let errors = [{ title: 'Adapter Error', detail: msg.trim(), status: responseData.status }];
return new AbortError(errors);
}

//From http://stackoverflow.com/questions/280634/endswith-in-javascript
function endsWith(string, suffix) {
if (typeof String.prototype.endsWith !== 'function') {
Expand Down

0 comments on commit 5e8183f

Please sign in to comment.