jeudi 15 octobre 2020

How to set custom response json in ember-data when dealing with errors

I'm using now:

  • ember: 3.8.1
  • ember-data: 3.10.0

I'm trying to send an error response from Grails API with some additional data. It looks something like this:

respond(
    status: HttpStatus.UNPROCESSABLE_ENTITY, 
    errors: errors
    additionalData: someMap
)

On the frontend side with Ember I'm trying to catch it with:

object.save().then(function () {
    // (...)
}).catch((response) => {
    // Here I want to access "response.additionalData"
    // (...)
});

Now, I know that ember-data has it's own way to handle and bind errors response (https://davidtang.io/2016/01/09/handling-errors-with-ember-data.html) but in ember-data: 2.10.0 I was able to catch and handle errors with additional data in catch with response.additionalData.

In version I'm using response.additionalData is always undefined and I can't get it in any way. It's coming from backend because I can see it in browser dev tools in response.

How can I achieve this in newest ember-data? I did try to write adapter and override handleResponse function but even my own CustomErrorClass still was like native one.

Any help would be appreciated. Thanks in advance!




Aucun commentaire:

Enregistrer un commentaire