jeudi 17 mars 2016

create a DS.Errors object in ember

Sometimes i have to go off of the ember-data path and execute ajax requests that do not fit in. I'd like have a normalized errors response for these. I was planning on using the DS.Errors object for this but there's little documentation on how to actually create these objects from scratch. Does anyone know the format expected to create on these objects since methods like add, remove, clear, etc. are all being deprecated?

This is what I was using, but those methods are being deprecated.

function (response) {
    let errs = Ember.get(response, 'errors') || [];

    let errors = DS.Errors.create();
    errs.forEach(function (error) {
        errors.add(error.field || 'base', error.detail);
    });


    if (errors.get('length') === 0) {
        errors.add('base', 'An error occurred :(');
    }

    return errors;
}

Aucun commentaire:

Enregistrer un commentaire