Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide some context about the http request when the RESTAdapter rejects #3862

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions packages/ember-data/lib/adapters/rest-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -743,9 +743,10 @@ export default Adapter.extend(BuildURLMixin, {
@param {Number} status
@param {Object} headers
@param {Object} payload
@param {String} errorMessage
@return {Object | DS.AdapterError} response
*/
handleResponse: function(status, headers, payload) {
handleResponse: function(status, headers, payload, errorMessage) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like we should not call the param errorMessage. It can be ok, or created in case of success. I would be ok with statusText, even if in case of obvious errors we "augment" the proper statusText.

if (this.isSuccess(status, headers, payload)) {
return payload;
} else if (this.isInvalid(status, headers, payload)) {
Expand All @@ -754,7 +755,7 @@ export default Adapter.extend(BuildURLMixin, {

let errors = this.normalizeErrorResponse(status, headers, payload);

return new AdapterError(errors);
return new AdapterError(errors, errorMessage);
},

/**
Expand Down Expand Up @@ -822,7 +823,8 @@ export default Adapter.extend(BuildURLMixin, {
response = adapter.handleResponse(
jqXHR.status,
parseResponseHeaders(jqXHR.getAllResponseHeaders()),
response || payload
response || payload,
jqXHR.statustext
);
}

Expand All @@ -847,7 +849,8 @@ export default Adapter.extend(BuildURLMixin, {
error = adapter.handleResponse(
jqXHR.status,
parseResponseHeaders(jqXHR.getAllResponseHeaders()),
adapter.parseErrorResponse(jqXHR.responseText) || errorThrown
adapter.parseErrorResponse(jqXHR.responseText) || errorThrown,
`Adapter operation failed ${type} ${url} ${jqXHR.status} (${jqXHR.statusText})`
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2188,21 +2188,23 @@ test("calls adapter.handleResponse with the jqXHR and json", function() {
});

test('calls handleResponse with jqXHR, jqXHR.responseText', function() {
expect(3);
expect(4);
var originalAjax = Ember.$.ajax;
var jqXHR = {
status: 400,
responseText: 'Nope lol',
statusText: 'Bad request',
getAllResponseHeaders: function() { return ''; }
};

Ember.$.ajax = function(hash) {
hash.error(jqXHR, jqXHR.responseText, 'Bad Request');
};

adapter.handleResponse = function(status, headers, json) {
adapter.handleResponse = function(status, headers, json, errorMessage) {
deepEqual(status, 400);
deepEqual(json, jqXHR.responseText);
equal(errorMessage, 'Adapter operation failed GET /posts/1 400 (Bad request)');
return new DS.AdapterError('nope!');
};

Expand Down