-
-
Notifications
You must be signed in to change notification settings - Fork 87
It should be possible to override handleResponse()
in an ember-data adapter
#211
Comments
Good timing! One of the big topics in the last working group meeting was tuning up the mixin to ensure it's 1:1 compatible with As an unrelated side note, it's possible to import the mixin from
|
Ok, I'm glad this is timely. I wasn't sure whether to log this as an issue on Thanks for the extra pointer about the |
hi, I'm having the same issue here. |
Ran into this issue myself. Any work around other than what @nelstrom suggested? |
Any updates on this? Almost 3 years no proper solution on this 🤔 |
@pankajparkar You have to override the ajax service. For example:
import AjaxService from 'ember-ajax/services/ajax';
export default AjaxService.extend({
handleResponse() { return this._super(...arguments); },
}); |
@c-emil Thanks, my |
Overriding handleResponse() in an ember-data adapter doesn't get called
I'm trying to get
ember-data
to use theember-ajax
service. I've run into a problem: one of my adapters overrides thehandleResponse()
method, but the method never seems to get called.Here's what I've got. My
app/adapters/applications.js
:The
AjaxSupport
mixin is copied directly from theember-ajax
source code.My
app/adapters/booking.js
adapter extends the application adapter and attempts to override thehandleResponse()
method:The API I'm working with uses a
400
status code where a422
would be more appropriate. I want to treat the400
response as anInvalidError
rather than aBadRequest
. Also, I'm trying to return aDS.InvalidError
instead of theInvalidError
supplied byember-ajax
, because I want to trigger theextractErrors()
method in the correspondingapp/serializers/booking.js
. (The ember-data store checks for an instance ofDS.InvalidError
)I've been able to get the desired behaviour by overriding the
handleResponse
method in myapp/services/ajax.js
file, like this:This version of
handleResponse()
does get called, whereas the method in my custom adapter does not. Previously (whenember-data
was not using theember-ajax
service), thehandleResponse()
method in myBookingAdapter
was called when ajax requests were made to the/bookings
endpoint. I was expecting that it would continue to work this way.I've also attempted to override the
isInvalidError
method with the same results: it works when used in myAjaxService
, but when used in myBookingAdapter
the code never gets called.The text was updated successfully, but these errors were encountered: