Breezejs [Q]未处理的拒绝原因(应该为空) [英] Breezejs [Q] Unhandled rejection reasons (should be empty)

查看:113
本文介绍了Breezejs [Q]未处理的拒绝原因(应该为空)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这几天,我学到了breezejs,durandaljs,所以我制作了一个spa应用程序供人们锻炼,但是breezejs(或q.js)经常发出错误消息


[Q]未处理的拒绝原因(应为空):[ proto.saveChanges@http:... s / jquery-1.9.1.js:2750\n]( Firefox



[Q]未处理的拒绝原因(应为空):(无堆栈)错误:遇到客户端验证错误-请参阅此上的entityErrors集合对象以获取更多详细信息( IE10,但是为什么删除实体会触发验证?


我对此感到失望使用breezejs,我到底在做什么!!!



我只是保存和删除客户,有时会发生上述错误,有时效果很好。(我很困惑感觉!:'((    )



这是我数据上下文的一部分


  var saveChanges = func tion(){
return manager.saveChanges()
.then(saveSuccess)
.fail(saveFailure); //。done()都不起作用
//
函数saveSuccess(){
console.log( Save Success!);
}
//
函数saveFailure(错误){
console.log(保存失败!);
抛出错误;
}
};


要保存客户:


  define(['modules / dataService'],function(datacontext){




  var ctor = function(){
this.entity = ko.observable();
};

ctor.prototype.activate = function(){
//问题代码-> [Q ]未处理的拒绝原因(应该为空)
//它将在调用激活时始终创建空客户
//由于每次都创建空客户而进入时发生错误。 b this.entity(datacontext.createEntity('Customer'));
};

ctor.prototype.saveClick = function(){
if(this.entity() .entityAspect.validateEntity())
datacontext.saveChanges();
else
console.log('validation error!');
};

return ctor;

});



删除客户


define(function(require){
var datacontext = require('modules / dataService ');
var vm = {
客户:ko.observableArray(),
activate:function(){
var self = this;
return datacontext.getCustomers(self.customers);
},
deleteCustomer:deleteCustomer
};
返回虚拟机;
//删除客户
函数deleteCustomer(customer){
vm.customers.remove(customer);
//将实体设置为已删除
的EntityState customer.entityAspect.setDeleted();
datacontext.saveChanges();
}
});


我认为我的代码可以正常工作,但是不能! / p>

我犯的致命错误在哪里?请让我知道。



谢谢!

解决方案

I知道这个线程已经存在了一年多了,但是我想我可以分享我的故事。



在使用微风+ angularJS时我遇到了同样的错误。经过一番研究,我弄清楚了:



我在整个实体的某些属性中传递了空值,而在数据库表中的那些字段被标记为NOT NULL。

p>

微风-saveChanges



在执行breeze.saveChanges时,要进行检查在内部标志上(第12743行::((.this.validationOptions.validateOnSave)...)



这是为了对照数据库架构对实体进行验证(又名



现在大多数时候,我们倾向于不带任何参数地调用saveChanges。并且错误不会在控制台中显示为一般验证错误消息。



我做了什么



我们将修复分为两部分:


  1. 在我的电话中添加一些代码以保存saveChanges in为了捕获这些错误并在控制台中显示更好的消息(请参见下面的代码)

  2. 修复数据库模式(即将NOT NOT NULL字段放松为NULLABLE)或设置一些默认值或强制执行

这是我现在用来捕获错误的代码片段: p>

  return manager.saveChanges(null,null,null,函数(错误){
console.log('breeze saveChanges返回一些错误:');

errors.entityErrors.forEach(function(e){
console.log(e.errorMessage,e);
});
}); //返回承诺


These days,i have learned breezejs,durandaljs, so i made an spa application for excersizing,but breezejs(or q.js) often gives out errors

[Q] Unhandled rejection reasons (should be empty): ["proto.saveChanges@http:...s/jquery-1.9.1.js:2750\n"] (Firefox)

[Q] Unhandled rejection reasons (should be empty):(no stack) Error: Client side validation errors encountered - see the entityErrors collection on this object for more detail (IE10, but why deleteing an entity triggers validation ?)

I feel disappointed to use breezejs, what on earth am i doing!!!

I just do saving and deleting customer, sometimes error occured as above, sometimes works fine.(how confused i am feeling! :'(     )

Here is part of my datacontext

  var saveChanges = function () {
    return manager.saveChanges()
        .then(saveSuccess)
        .fail(saveFailure); //.done() does not work either
    //
    function saveSuccess() {
        console.log("Save Success!");
    }
    //
    function saveFailure(error) {
        console.log("Save Failure!");
        throw error;
    }
};

To save a customer:

define(['modules/dataService'], function (datacontext) {

var ctor = function () {
    this.entity = ko.observable();
};

ctor.prototype.activate = function () {
    //problem code --> [Q] Unhandled rejection reasons (should be empty)
    //it will always create empty Customer when activate is called. 
    //so error occured when i switch in because of creating empty Customer every time.
    this.entity(datacontext.createEntity('Customer'));
};

ctor.prototype.saveClick = function () {
    if (this.entity().entityAspect.validateEntity())
        datacontext.saveChanges();
    else
        console.log('validation error!');
};

return ctor;

});

To delete a customer

define(function (require) { var datacontext = require('modules/dataService'); var vm = { customers: ko.observableArray(), activate: function () { var self = this; return datacontext.getCustomers(self.customers); }, deleteCustomer: deleteCustomer }; return vm; //delete customer function deleteCustomer(customer) { vm.customers.remove(customer); //Sets the entity to an EntityState of 'Deleted' customer.entityAspect.setDeleted(); datacontext.saveChanges(); } });

I think my code would work fine, but it can't!

Where is the fatal error i make? plz let me know.

Thanks in advance!

解决方案

I know this thread has been here for more than a year now but I thought I could share my story.

I just got the same error while using breeze + angularJS. After some research, I figured it out:

I was passing null values in some of the entitie's properties while those fields in the database table where marked as NOT NULL.

Breeze - saveChanges

In the implementation of breeze.saveChanges, a check is done on a internal flag (line 12743 approx : if (this.validationOptions.validateOnSave) ...)

This is to enable verification of the entity against the database schema (aka the metadata).

Now most of the time we tend to call saveChanges without any parameters. And the error does not show otherwise then in the console as a general validation error message.

What have i done

We'll my fix was in 2 parts:

  1. Add some code in my calls to saveChanges in order to trap these errors and display a better message in the console (see code below)
  2. Fix either the DB schema (i.e. Relax NOT NULL fields to NULLABLE) OR set some default values OR enforce the business logic by adding required attributes to input controls.

Here's a snippet of the code I now use to trap the errors:

return manager.saveChanges(null, null, null, function (errors) {
    console.log('breeze saveChanges returned some errors: ');

    errors.entityErrors.forEach(function(e) {
        console.log(e.errorMessage, e);
    });
}); // return promise

这篇关于Breezejs [Q]未处理的拒绝原因(应该为空)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆