Search code examples
javascriptcallbackbreeze

Breeze entityManager calling fail callback even on success


The entityManager instance is calling fail callback even on success. Checking the network activity, the requests returns 200 and with expected data.
If I remove the .fail() method from the chain it works just fine, with it I get that the error object is undefined.

My WebAPI is running with CORS enabled and as we're in early development, everything is fully allowed (headers, methods, any origin, credentials).

Here is the JavaScript code:

function getResumoPromocoes() {
            var resumoPromocoes = [];
            var orderBy = "visualizacoes";

            return EntityQuery.from("Promocoes")
                .select("id, titulo, descricao, iniciaEm, expiraEm")
                .orderBy(orderBy)
                .toType("Promocao")
                .using(manager)
                .execute()
                .then(function(data) {
                    resumoPromocoes = data.results;
                    log("Resumo das Promoções recebidas", resumoPromocoes.length, true);
                    return resumoPromocoes;
                })
                .fail(_queryFailed(error));
        }

Is it proper to pass the fail callback after the success one in the .then() method? Same thing with .fail()?


Solution

  • Not sure if this is the issue but the ";" after the then clause is almost certainly an error and the argument to '.fail' needs to be a function not the result of executing a function. So try this instead.

    .then(function(data) {
    ...
    })
    .fail(_queryFailed);