ajax - Bacon.retry not retrying on 'Access-Control-Allow-Origin' errors -
i have buggy web service sporadically sends 500-error "xmlhttprequest cannot load http://54.175.3.41:3124/solve. no 'access-control-allow-origin' header present on requested resource. origin 'http://local.xxx.me:8080' therefore not allowed access. response had http status code 500."
i use bacon.retry wrap ajax call. when fails, it'll retry. however, notice stream won't produce value when server fails. it's if bacon.retry doesn't retry (which in fact what's happening, when under hood in dev console).
i'm using baconjs 0.7.65.
the observable bacon.retry looks this:
var ajaxrequest = bacon.frompromise($.ajax(//...)); var observable = bacon.retry({ source: function() { return ajaxrequest; }, retries: 50, delay: function() { return 100; } });
the code calls observable looks this:
stream.flatmap(function(valuesorobservables) { return bacon.fromarray(valuesorobservables) .flatmapconcat(function(valueorobservable) { switch(valueorobservable.type) { //we calculate beforehand case 'value' : return valueorobservable.value; case 'observable' : return bacon.fromarray(valueorobservable.observables) .flatmapconcat(function(obs) { return obs; }) } }) })
observations:
- if add error handler observable, still not work.
- for reason, #retry called 50 times when succeeds.
i'm not sure entirely bacon in rxjs ajax calls wrapped around asyncsubject
s re subscribing error'd stream fire off same error, have re-execute method produces observable.
so retry (again sorry in rx):
rx.observable.defer(() => callajaxreturnobservable()) .retry(50) .subscribe();
edit 1
trying baconize , clarify earlier answer:
var observable = bacon.retry({ source : function() { return bacon.frompromise($.ajax(/**/)); }, retries : 50, delay: function() { return 100; } });
if don't have frompromise
inside of source
function, every time retry downstream receive same exception.
Comments
Post a Comment