What's is the right way to trigger an error callback in Backbone if my response has a certain flag? - backbone.js

This is my use case: I call fetch on a collection and receive a JSON from my server yet I have an error flag. This will always trigger the success flow, and I can detect the error by 2 means:
In my parse method - which is ugly.
By not using the success option, and using the Deferred's Done callback to check for the error. This is ugly as well since I have to call parse myself afterwards.
This would be solveable if Backbone had a validate function on collection but it doesn't...
Any suggestions?
EDIT: I know there's a way to do it by supplying my own Sync method but I got a bit lost there...

good question.. I'm not sure it's so bad to work with the parse method. It's name doesn't fit but it's all you've got in the natural path of the code and I guess you can just return an empty list without breaking anything.
The question to me is what is the cause of the error? If it's, say, a permissions thing (or some other error covered by the http protocol), you could return an error code from the server which should trigger your error callback..

Related

#stomp/stompjs latest, subscription() getting in unexpected responses

I am using the latest #stomp/stompjs package in react and it appears to be not working as described so I was wondering if anyone know what was going on.
When I do stompClient.subscribe() I expect only 1 message from the backend. But I normally get an empty object first "{}" and then then the callback goes off again I then get the expect json string. Sometimes I get a 3rd callback with the same json string. I know the page is being redrawn with the new data by react, but I would not think this would cause the callback to go off a second time. Also, this behavior seems to be only for large json string responses. Small response status json objects never returned multiple times in the callback (just the {} object the first time). My workaround was to have a flag that I sett when I do the send command and then is set to false when I get a valid response back. Any extract responses are skipped not saved in the useState hook so react doesn't redraw again.
The second thing I see is sometimes the wrong response is received by the callback. The bookmark paths would be like /location/read and /location/readBL but the response for /location/read would be read by the readBL subscription callback sometimes. This happens 1 out of 10, but I don't understand why it would doing that. The workaround I did is to have the main object key have different words like {camera: {}) and {cameraBL: {}} and see if the object key matches in the expected key in the callback, otherwise skip it.
I assume react is somehow responsible for all this. So, has anyone seen this in their stomp code and know what's going on?
I have inserted flags or filtering to workaround the problem. I have not seen any description of these problems on the web and the stomp home page doesn't talk about any of this.

Not able to set list2 in Adobe Launch in custom code

I am trying to set list2 in my analytics call through custom code but it is not getting set.
This issue comes with s.tl() only while with s.t() method, it is triggered correctly.
Below is the code :-
s.addEvent("event12", true);
s.linkTrackVars = "list2";
s.list2 = "Data"
s.tl(this, "d", "Download", s);
If I place logger just before beacon call, it shows the value. However, when I click the button and check for same, only "event12" get fired and not "list2".
Any help would be highly appreciated.
Just tested your code on lululemon:
Conclusion:
You're overwriting either the listvar or the linkTrackVars somewhere else. As #Crayton Mentioned above, doPlugins would be a good spot for it.
But it actually can be overwritten anywhere. In any rule that fires prior, or the s code, or any DE affected.
Paste your code into the console. Execute. Do you see the listvar populated? If yes, then your problem is in rules, so check them. You're not supposed to reassign linktrackvars. Always use the s.apl() plugin.
If no, however, then your problem is definitely in doPlugins. Sometimes I have it when I have silent catches in s code. Pageviews would have all vars populated, but links would have mixed results. Check your error reporting in the catches in doPlugins. I suggest having all code in doPlugins in a try catch.

Under what circumstances will Cake3's HTTP Client return a NULL response?

I'm trying to connect to an API using Cake's HTTP Client. But the response object that is returned is null, no status code, no body, nothing, just null. It's worth noting that if I visit the URL from a browser I get the desired results.
I asked a question to see if I was doing anything stupid which is here. Judging by the lack of responses I dont think I have any silly syntax errors.
So now I'm wondering what has to happen for the Cake3 HTTP Client to return NULL rather than a response object? Hopefully knowing what could be going wrong will show me where to look.
Under what circumstances will Cake3's HTTP Client return a NULL response?
When the adapter returns an empty array (ie no response objects), or a non-array value. The client uses array_pop() on the adapters return value, which would return null in case of an empty array, or a non-array value.
In order to debug the problem, dig into the adapter code and check where things are going wrong. Unless you are using a custom adapter, that would be \Cake\Network\Http\Adapter\Stream::_send().
.../src/Network/Http/Adapter/Stream.php#L258-L277
.../src/Network/Http/Adapter/Stream.php#L94-L110
The response being malformed, like not containing a HTTP/... header could for example be one reason for such a failure. Maybe what you have there isn't a response at all, maybe the request didn't even made it through your firewall or something, but didn't caused an error. So, I'd suggest starting with inspecting $meta and $content and going from there.

"conn 0x7f7d6c001610 error: i=-2 errno=11 state=4 rc=3 br=721" Appearing in nxweb log

I am writing a custom handler and wanted to see how stable it is and just let my browser request the same URL over and over. It doesn't crash but I get some messages like the one in the title.
I.e.
conn 0x7f7d6c001610 error: i=-2 errno=11 state=4 rc=3 br=721
This also happens when I execute the "hello" example but far less often.
Could you give me any pointers as to why this happens? Do I have to fix this?
This error report is not critical. This means connection to client dropped for some reason before request has been fulfilled.

Backbone.js TypeError thrown on model.save

In my current Backbone app, I have no problems creating or destroying
models. The changes propagate to my server without any problems. But
whenever I try to do a model.save(attributes), I see a TypeError
thrown at this line: https://github.com/documentcloud/backbone/blob/master/backbone.js#L117
The model is updated on the (Rails) server, but something breaks
afterward. Here's the stack trace. (Sorry, line numbers refer to
concatenated JS files.)
Backbone.Events.trigger() at application.js:11574
_.extend._onModelEvent() at application.js:12092
d() at (internal script):1426Backbone.Events.trigger() at
application.js:11574
_.extend.change() at application.js:11808
_.extend.set() at application.js:11680
_.extend.save() at application.js:11753
Map.mapMoveGeoPointMode() at app.js:741
(anonymous function)() at app.js:894
jQuery.event.handle() at application.js:2966
jQuery.event.add.elemData.handle.eventHandle() at application.js:2600
In previous applications, I've had no little problems on saving models
like this. Any suggestions for what to look at?
Note: I don't think I'm repeating this fellow's problem of trying to save a model with no URL.
Given that the model is updated properly on the server, I don't think this has anything to do with the save() function itself, but rather with the change event it's triggering - I think you could test this simply by calling myModel.trigger('change') and seeing if that throws the same error.
My best guess as to why this is happening is that somewhere along the way you're binding something other than a function - e.g. an undefined variable - to the change event. I'd look for an error like this:
myModel.bind('change', this.misspelledMethod, this);
but it's pretty much impossible to debug further without seeing actual code, not just a stack trace.
It looks like you are binding to an event on the model and passing in something that isn't a valid function. Make sure all of your bind statements pass in functions:
var FUNC = function() {};
MyModel.bind('reset' FUNC);

Resources