Null object comparison in Mockjax causing exception in jQuery - ajax

I am attempting to send back stub data via the Mockjax library. The practice is working out for the most part with one exception: the library fails when it tries to do a null comparison of the live and mock data. The Mockjax code is below, the data being sent in is the same as the data in the code snippet.
The error occurs in jQuery (line 630 in my file) when it attempts to find the length of a null object inside of $.each. The version of Mockjax is 1.5.2, the version of jQuery is 1.7.1.
$.mockjax({
url: "service/endpoint",
data: {
elementId : "207710",
floorId : null
},
responseTime: 0,
proxy: '../../07-29-13-all-true.json'
});
Has anyone encountered this and what was your solution? I send null in multiple service calls, so changing that code isn't a great solution at the time.
Any suggestion would be helpful.

Turns out that this was a bug in Mockjax, the fix is in testing now. You can read more about the bug here: https://github.com/appendto/jquery-mockjax/issues/106

Related

Why do I get error when trying to add file attachments?

I am trying to use the method addFileAttachmentAsync() in office.js library.
This is the signature of the method I am using:
item.addFileAttachmentAsync(uploadLink, fileJson.name, { asyncContext: null }, function (asyncResult) { });
uploadLink is a string and here is an example of a file I'm trying to upload: https://xdr.purequad.com:6443/files/1b783908-a259-4839-93e2-18fe3248b943_moto.pdf.xdr
The file above is about ~3MB, but when I use a file under 1MB everything works perfectly.
Afterwards it throws this Exception :
Line: 9
Error: Unable to get property 'isInstanceOfType' of undefined or null reference
Also I have to mention this behavior happens only in IE11, while Google Chrome does not throw any exception at all and still does not work.
EDIT: The function was being interrupted before it ended properly! Check my comment.
I have solved the issue myself. When using addFileAttachmentAsync() because it's an async call one should never interrupt the task-pane with Office.context.ui.closeContainer() which was my case. Otherwise it will generate unexpected behavior.

Parse Cloud Code runs on client side but not on server side

I wrote this large parse code for Parse Cloud Code that queries a row based on it's objectId. I wrote this all on my client-side and tested it with my localized html code. Everything works great! But, once I push it to the server and attempt to run I get Error 141 : "An error has occured"
Clearly, this is massively unhelpful. So, I broke the code down to the most basic call I can make, shown below:
function getCardPacks(request, response)
{
var myTable = Parse.Object.extend("myTable");
var query = new Parse.Query(myTable);
query.get(request.params.tabId,
{
success:function(results)
{
response.success();
},
error:function(error)
{
response.error(error);
}
},function(error)
{
console.log(error);
});
I still get the 141. I verified that the params I send this function are not null, but maybe they are getting undefined before they reach the function? I really have no idea what is wrong here.
Has this happened to anyone else? Or, is there a way I can get debug logs from the server end so I could determine if a val is null or find out where the script stops?
Well you can check the logs on Parse.com on your app. I'm confused what you are using cloud code for. If you are just querying a table, then you should be able to do that using the Parse javascript sdk. You can see how to set that up here. https://www.parse.com/apps/quickstart?app_id=syncup-staging#parse_data/web/existing

StackOverflowException in solrnet

We have the same requirement of passing huge data like http://bugsquash.blogspot.in/2010/12/customizing-solrnet.html, we tried the following.
1) Increased the requestHeaderSize to Int32.MaxValue - stackoverflow exception
2) Used PostSolrconnection - got the StackOverflow exception.
3) Downloaded the source of solrnet and added as project reference - Stackoverflow exception
Then even we changed to GET, we are getting the StackOverflow exception. The error is coming when we have more than 500 reference ids. If we have less values, it works.
This is how we are calling,
searchResults = solrPost.Query(new SolrMultipleCriteriaQuery(new[] 
                { 
                    query 
                 }), 
                      new SolrNet.Commands.Parameters.QueryOptions 
                      { 
                          Fields = new[] { "*", "score" }, 
                          Start = pageSize, 
                          Rows = 40, 
                          OrderBy = listSort 
                      }); 
Any ideas?
EDIT:
We tried requesting solr using HttpRequest and identified as maxBooleanClause issue and then POST started working through HttpRequest. But using SolrNet the error is occurred and it is happening at serializing the query object. queryserializer.serialize(Query)
Wondering why step 2 didn't work which is the exact fix for the long Get request issue, i.e. to switch over to Post request.
Chances are there is an issue with the piece of code where you are initialising SolrNet to use PostSolrConnection instead of the default SolrConnection. Need to look at the bit of code which gets you the instance of solrPost object. Take another look at it and post it here.
Unfortunately the SolrNet didn't work due to stackoverflow error while serializing the query parameters. Alternate workaround is posted http://smartcoder.in/solrnetstackoverflow/

Meteor 0.5.9: replacement for using Session in a server method?

So, I was attempting to do something like the following:
if(Meteor.isServer){
Meteor.methods({connect_to_api: function(vars){
// get data from remote API
return data;
}});
}
if(Meteor.isClient){
Template.myTpl.content = function(){
Meteor.call('connect_to_api', vars, function(err,data){
Session.set('placeholder', data);
});
return Session.get('placeholder');
};
}
This seemed to be working fine, but, of course, now breaks in 0.5.9 as the Session object has been removed from the server. How in the world do you now create a reactive Template that uses a server-only (stuff we don't want loading on the client) method call and get data back from that Method call. You can't put any Session references in the callback function because it doesn't exist on the server, and I don't know of any other reactive data sources available for this scenario.
I'm pretty new to Meteor, so I'm really trying to pin down best-practices stuff that has the best chance of being future-proof. Apparently the above implementation was not it.
EDIT: To clarify, this is not a problem of when I'm returning from the Template function. This is a problem of Session existing on the server. The above code will generate the following error message on the server:
Exception while invoking method 'connect_to_api' ReferenceError: Session is not defined
at Meteor.methods.connect_to_api (path/to/file.js:#:#)
at _.extend.protocol_handlers.method.exception ... etc etc
Setting the session in the callback seems to work fine, see this project I created on github: https://github.com/jtblin/meteor_session_test. In this example, I return data in a server method, and set it in the session in the callback.
There are 2 issues with your code:
1) Missing closing brace placement in Meteor.methods. The code should be:
Meteor.methods({
connect_to_api: function(vars) {
// get data from remote API
return data;
}
});
2) As explained above, you return the value in the session, before the callback is completed, i.e. before the callback method had the time to set the session variable. I guess this is why you don't see any data in the session variable yet.
I feel like an idiot (not the first time, not the last). Thanks to jtblin for showing me that Session.set does indeed work in the callback, I went back and scoured my Meteor.method function. Turns out there was one spot buried in the code where I was using Session.get which was what was throwing the error. Once I passed that value in from the client rather than trying to get it in the method itself, all was right with the world.
Oh, and you can indeed order things as above without issue.

Breezejs How to debug cause of TypeError in query response

I'm attempting to use Breeze to query a ASP.Net Web API endpoint and the query fails - with the data object containing:
internalError: TypeError
arguments: Array[2]
0: "createCtor"
1: null
length: 2
__proto__: Array[0]
get message: function () { [native code] }
get stack: function () { [native code] }
set message: function () { [native code] }
set stack: function () { [native code] }
type: "non_object_property_load"
The data object has a message (and responsetext) property which contains the full json response from the query which looks ok and the metadata thats been generated matches the response - it also records status 200 for the response
So I'm guessing there is some kind of issue mapping the response to an object on the client side?
I'm using the NuGet package for Breeze version 0.85.2
I can get the sample ToDo project to run fine on the same environment
My project does use domain objects, contexts etc all from different assemblies and namespaces but I understood thats supported in this version?
Also that one of the properties is an enum - in the metadata this is defined as {\"name\":\"State\",\"type\":\"Edm.Self.State\",\"nullable\":\"false\"}] but in the response is comes through as an integer
Looking for tips on how to debug this further on the client side
Update
comparing the working sample with my code, the error looks to be coming from this function:
/**
Returns the constructor for this EntityType.
#method getEntityCtor
#return {Function} The constructor for this EntityType.
**/
ctor.prototype.getEntityCtor = function () {
if (this._ctor) return this._ctor;
var typeRegistry = this.metadataStore._typeRegistry;
var aCtor = typeRegistry[this.name] || typeRegistry[this.shortName];
if (!aCtor) {
var createCtor = v_modelLibraryDef.defaultInstance.createCtor;
if (createCtor) {
aCtor = createCtor(this);
} else {
aCtor = function() {
};
}
}
this._setCtor(aCtor);
return aCtor;
};
The defaultInstance property on v_modelLibraryDef is undefined in my running code - what am I missing on the configuration of breeze for that to happen?
Update 2 - Resolved but why
Ok so I got this working - I was missing a reference to knockout (which I was planning to use but hadn't got that far) - I was a little bit misled by the breeze prerequisites which don't mention knockout so if anyone can explain how I could have got this working without knockout and if its a bug then the points are yours
Got same error, and referencing knockout.js helped(I'm using angularjs for my app)
manager.executeQuery(query).then(function(data) {
console.log(data);
});
But.
It seems, that data-mapper works with knockout by default, so we have XHR results as K.O. model with observables.
so I added breeze.config.initializeAdapterInstance("modelLibrary", "backingStore", true);
and now I don't receive data.results as observable collection.
Hope my answer will help.
Sorry you struggled Richard. We'll try to learn from it and spare the next person the pain you endured.
FWIW, we do not say that Knockout is a prerequisite ... because KO is not a prerequisite. You can use Angular or Backbone instead and we anticipate other alternatives in future.
We don't want to drown you in configuration options when you're just learning Breeze. So we picked KO as the default model library (just as jQuery is the default AJAX provider and Web API is the default "dataservice" technology). We say so in numerous places; prerequisites looks like another good place to mention it.
As it happens, you intended to go with KO anyway so no configuration would have been necessary. Most folks start with something like the MVC template which includes KO and loads it for you in the Index.cshtml.
Apparently you started from a clean slate ("ASP Empty Web Application" perhaps?). The Breeze Web API NuGet package strives to be spare and therefore does not include KO. We figured (incorrectly) that you would add it yourself ... in the right script order ... if you wanted to use KO. Clearly we could do a better job of documenting this particular development path ... especially as we like it so much ourselves. Thanks for pointing it out.
The other problem is that the exception was not helpful. You can see from other attempts to answer your question that even folks with Breeze experience couldn't recognize what was wrong. We'll look to see if we can detect the missing script a little earlier and throw an exception with a better message.
This error looks like it has to do with one of your Entity type constructors. I'm guessing that you are calling the 'registerEntityTypeCtor' method somewhere in your code. If so, then I would put a breakpoint in the constructor that you are registering there.
Per your other comment, .NET enums are supposed to get converted into integers on the breeze client. This is the only 'primitive' datatype that could support them. They will get converted back to enums on the server when you call 'EntityManager.saveChanges'
Breeze does not require 'knockout', you can use either 'angularjs' or 'backbone' as well. We simply default the breeze client to knockout if you do not specify another library. See the 'breeze.config.initializeAdapterInstance' topic here. We do need to a better job of documenting this.
Every time I get an error at which the Message property of the response is the data in json format means I have a bug in the function that runs after getting the data.
Example:
dataservice.getPalanca(routeData.PalancaID)
.then(function (data) {
self.palanca(data.results[0]);
})
.fail(function (error) {
console.log(error); /*if I get here and error.Message == correct json almost always means error in .then function*/
toastr.error("Ha ocurrido un error al obtener los datos");
});
I hope I help you.

Resources