lundi 27 juin 2016

Handling Errors with RESTSerializer

Using ember and ember-data 2.6 versions, I'm trying to get error handling working but running into issues. I'm using the RESTSerializer and I'm sending the following payload to my server:

{
    "brand": {
        "name": null,
        "description": null,
    }
}]

Since name cannot be null, this is what I'm sending back as my response:

{
    "errors": [{
        "code": null,
        "detail": "may not be null",
        "status": null,
        "title": null,
        "source": {
            "pointer": "brand/name",
            "parameter": null
        }
    }]
}

In my route, I am doing the following in the save promise on failure:

console.log(savedBrand.get('isValid')); // logs false
console.log(savedBrand.get('errors').toArray()); // logs [ ]

There doesn't seem to be a lot of detailed documentation on how this all works so I'm using this article as a starting point. I'm unsure as to why toArray() returns an empty array instead of my error that I'm returning in the JSON.




Aucun commentaire:

Enregistrer un commentaire