Wondering what is the best way to handle a failure to save on the server-side? For example, suppose my Ember app calls record.save()
and the server is unable to actually do the save, possibly for legit reasons (for example, the record was modified by someone else, or some sort of complex validation wasn’t met).
If my server returns a 4xx, this seems wrong, REST-wise, but is also problematic because the client-side copy of the model is now out of date.
If my server returns a 2xx, how is the client to know that the save failed? If I re-GET, the server returns a 304, leaving the client out of sync again.
When I’ve designed REST APIs before, I’ve typically included an envelope that would allow encapsulating this data, e.g.
{
success: true,
record: { the record as normal }
}
// vs.
{
success: false,
errorMessage: { "email address is already taken" }
}
This format doesn’t seem to play well with Ember Data, so I’m wondering if there’s a more canonical way that Ember Data expects this to work?