How to use on_error method in wpt

Best JavaScript code snippet using wpt

__init__.py

Source:__init__.py Github

copy

Full Screen

...124 :param func on_success: An optional function to call if/when the API call succeeds.125 on_success callback takes no parameters.126 """127 if not __is_init():128 on_error(ERROR_INIT, __error_message(ERROR_INIT))129 return130 if not isinstance(user_id, six.string_types + (Number,)):131 on_error(ERROR_USER_ID, __error_message(ERROR_USER_ID))132 return133 if not isinstance(previous_id, six.string_types + (Number,)):134 on_error(ERROR_PREVIOUS_ID, __error_message(ERROR_PREVIOUS_ID))135 return136 data = dict(137 user_id=user_id,138 previous_id=previous_id,139 )140 try:141 resp = requests.post(142 "%s/identify" % __BASE_URL,143 data=json.dumps(data),144 headers=__HEADERS,145 )146 if resp.status_code >= 200 and resp.status_code < 400:147 on_success()148 else:149 on_error(ERROR_UNKNOWN, resp.text)150 except requests.exceptions.ConnectionError:151 on_error(ERROR_CONNECTION, __error_message(ERROR_CONNECTION))152def identify(user_id, previous_id=None, group_id=None, group_attributes=None,153 first_name=None, last_name=None, email=None,154 phone_number=None, apns_tokens=None, gcm_tokens=None,155 attributes=None, on_error=None, on_success=None):156 """ Identifying a user creates a record of your user in Outbound. Identify157 calls should be made prior to sending any track events for a user.158 :param str | number user_id: the id you use to identify a user. this should159 be static for the lifetime of a user.160 :param str | number previous_id: OPTIONAL the id you previously used to identify the user.161 :param str | number group_id: OPTIONAL the id that identifies a group of users the current user162 belongs to.163 :param dict group_attributes: OPTIONAL An optional dictionary of attributes that are shared164 among the group this user belongs to.165 :param str first_name: OPTIONAL the user's first name.166 :param str last_name: OPTIONAL the user's last name.167 :param str email: OPTIONAL the user's email address.168 :param str phone_number: OPTIONAL the user's phone number.169 :param str | list apns_tokens: OPTIONAL the device tokens for the user's iOS170 devices. If a single string is given it is put into a list.171 :param str | list gcm_tokens: OPTIONAL the device tokens for the user's Android172 devices. If a single string is given it is put into a list.173 :param dict attributes: An optional dictionary with any additional freeform174 attributes describing the user.175 :param func on_error: An optional function to call in the event of an error.176 on_error callback should take 2 parameters: `code` and `error`. `code` will be177 one of outbound.ERROR_XXXXXX. `error` will be the corresponding message.178 :param func on_success: An optional function to call if/when the API call succeeds.179 on_success callback takes no parameters.180 """181 on_error = on_error or __on_error182 on_success = on_success or __on_success183 if not __is_init():184 on_error(ERROR_INIT, __error_message(ERROR_INIT))185 return186 if not isinstance(user_id, six.string_types + (Number,)):187 on_error(ERROR_USER_ID, __error_message(ERROR_USER_ID))188 return189 data = __user(190 first_name,191 last_name,192 email,193 phone_number,194 apns_tokens,195 gcm_tokens,196 attributes,197 previous_id,198 group_id,199 group_attributes,)200 data['user_id'] = user_id201 try:202 resp = requests.post(203 "%s/identify" % __BASE_URL,204 data=json.dumps(data),205 headers=__HEADERS,206 )207 if resp.status_code >= 200 and resp.status_code < 400:208 on_success()209 else:210 on_error(ERROR_UNKNOWN, resp.text)211 except requests.exceptions.ConnectionError:212 on_error(ERROR_CONNECTION, __error_message(ERROR_CONNECTION))213def track(user_id, event, first_name=None, last_name=None, email=None,214 phone_number=None, apns_tokens=None, gcm_tokens=None,215 user_attributes=None, properties=None, on_error=None, on_success=None, timestamp=None):216 """ For any event you want to track, when a user triggers that event you217 would call this function.218 You can do an identify and track call simultaneously by including all the219 identifiable user information in the track call.220 :param str | number user_id: the id you user who triggered the event.221 :param str first_name: OPTIONAL the user's first name.222 :param str last_name: OPTIONAL the user's last name.223 :param str email: OPTIONAL the user's email address.224 :param str phone_number: OPTIONAL the user's phone number.225 :param str | list apns_tokens: OPTIONAL the device tokens for the user's iOS226 devices. If a single string is given it is put into a list.227 :param str | list gcm_tokens: OPTIONAL the device tokens for the user's Android228 devices. If a single string is given it is put into a list.229 :param dict user_attributes: An optional dictionary with any additional230 freeform attributes describing the user.231 :param dict properties: An optional dictionary with any properties that232 describe the event being track. Example: if the event were "added item to233 cart", you might include a properties named "item" that is the name234 of the item added to the cart.235 :param func on_error: An optional function to call in the event of an error.236 on_error callback should take 1 parameter which will be the error message.237 :param func on_success: An optional function to call if/when the API call succeeds.238 on_success callback takes no parameters.239 """240 on_error = on_error or __on_error241 on_success = on_success or __on_success242 if not __is_init():243 on_error(ERROR_INIT, __error_message(ERROR_INIT))244 return245 if not isinstance(user_id, six.string_types + (Number,)):246 on_error(ERROR_USER_ID, __error_message(ERROR_USER_ID))247 return248 if not isinstance(event, six.string_types):249 on_error(ERROR_EVENT_NAME, __error_message(ERROR_EVENT_NAME))250 return251 data = dict(user_id=user_id, event=event)252 user = __user(253 first_name,254 last_name,255 email,256 phone_number,257 apns_tokens,258 gcm_tokens,259 user_attributes,260 None, None, None)261 if user:262 data['user'] = user263 if properties:264 if isinstance(properties, dict):265 if len(properties) > 0:266 data['properties'] = properties267 else:268 sys.stderr.write('Invalid event properties given. Expected dictionary. ' +269 'Got %s' % type(properties).__name__)270 if timestamp:271 data['timestamp'] = timestamp272 else:273 data['timestamp'] = int(time.time())274 try:275 resp = requests.post(276 "%s/track" % __BASE_URL,277 data=json.dumps(data),278 headers=__HEADERS,279 )280 if resp.status_code >= 200 and resp.status_code < 400:281 on_success()282 else:283 on_error(ERROR_UNKNOWN, resp.text)284 except requests.exceptions.ConnectionError:285 on_error(ERROR_CONNECTION, __error_message(ERROR_CONNECTION))286def __subscription(user_id, unsubscribe, all_campaigns=False, campaign_ids=None, on_error=None, on_success=None):287 on_error = on_error or __on_error288 on_success = on_success or __on_success289 if not __is_init():290 on_error(ERROR_INIT, __error_message(ERROR_INIT))291 return292 if not isinstance(user_id, six.string_types + (Number,)):293 on_error(ERROR_USER_ID, __error_message(ERROR_USER_ID))294 return295 if not all_campaigns and (not isinstance(campaign_ids, (list, tuple)) or len(campaign_ids) == 0):296 on_error(ERROR_TOKEN, __error_message(ERROR_CAMPAIGN_IDS))297 return298 url = '/'.join([__BASE_URL, ('unsubscribe' if unsubscribe else 'subscribe'), ('all' if all_campaigns else 'campaigns')])299 data = dict(300 user_id=user_id,301 )302 if not all_campaigns:303 data['campaign_ids'] = campaign_ids304 try:305 print __HEADERS306 resp = requests.post(307 url,308 data=json.dumps(data),309 headers=__HEADERS,310 )311 if resp.status_code >= 200 and resp.status_code < 400:312 on_success()313 else:314 on_error(ERROR_UNKNOWN, resp.text)315 except requests.exceptions.ConnectionError:316 on_error(ERROR_CONNECTION, __error_message(ERROR_CONNECTION))317def __device_token(platform, register, user_id, token='', all=False, on_error=None, on_success=None):318 on_error = on_error or __on_error319 on_success = on_success or __on_success320 if not __is_init():321 on_error(ERROR_INIT, __error_message(ERROR_INIT))322 return323 if not isinstance(user_id, six.string_types + (Number,)):324 on_error(ERROR_USER_ID, __error_message(ERROR_USER_ID))325 return326 if not all and not isinstance(token, six.string_types):327 on_error(ERROR_TOKEN, __error_message(ERROR_TOKEN))328 return329 try:330 data = dict(331 user_id=user_id,332 )333 if all:334 data["all"] = True335 else:336 data["token"] = token337 resp = requests.post(338 "%s/%s/%s" % (__BASE_URL, platform, 'register' if register else 'disable'),339 data=json.dumps(data),340 headers=__HEADERS,341 )342 if resp.status_code >= 200 and resp.status_code < 400:343 on_success()344 else:345 on_error(ERROR_UNKNOWN, resp.text)346 except requests.exceptions.ConnectionError:347 on_error(ERROR_CONNECTION, __error_message(ERROR_CONNECTION))348def __user(first_name, last_name, email, phone_number, apns_tokens,349 gcm_tokens, attributes, previous_id, group_id, group_attributes):350 data = dict()351 if previous_id:352 data['previous_id'] = previous_id353 if group_id:354 data['group_id'] = group_id355 if group_attributes:356 if isinstance(group_attributes, dict):357 if len(group_attributes) > 0:358 data['group_attributes'] = group_attributes359 else:360 sys.stderr.write('Invalid group attributes given. Expected dictionary. ' +361 'Got %s' % type(group_attributes).__name__)362 if first_name:363 data['first_name'] = first_name364 if last_name:365 data['last_name'] = last_name366 if email:367 data['email'] = email368 if phone_number:369 data['phone_number'] = phone_number370 if apns_tokens:371 if isinstance(apns_tokens, six.string_types):372 apns_tokens = [apns_tokens]373 if isinstance(apns_tokens, (list, tuple)):374 data['apns'] = apns_tokens375 else:376 sys.stderr.write('Invalid APNS tokens given. Expected string or ' +377 'list of strings. Got %s' % type(apns_tokens).__name__)378 if gcm_tokens:379 if isinstance(gcm_tokens, six.string_types):380 gcm_tokens = [gcm_tokens]381 if isinstance(gcm_tokens, (list, tuple)):382 data['gcm'] = gcm_tokens383 else:384 sys.stderr.write('Invalid GCM tokens given. Expected string or ' +385 'list of strings. Got %s' % type(gcm_tokens).__name__)386 if attributes:387 if isinstance(attributes, dict):388 if len(attributes) > 0:389 data['attributes'] = attributes390 else:391 sys.stderr.write('Invalid user attributes given. Expected dictionary. ' +392 'Got %s' % type(attributes).__name__)393 return data394def __error_message(code):395 return {396 ERROR_INIT: "init() must be called before identifying any users.",397 ERROR_USER_ID: "User ID must be a string or a number.",398 ERROR_EVENT_NAME: "Event name must be a string.",399 ERROR_CONNECTION: "Unable to connect to Outbound.",400 ERROR_UNKNOWN: "Unknown error occurred.",401 ERROR_TOKEN: "Token must be a string.",402 ERROR_CAMPAIGN_IDS: "One or more campaigns must be specified.",403 ERROR_PREVIOUS_ID: "Previous must be a string or a number.",404 }.get(code, "Unknown error")405def __on_error(code, err):406 pass407def __on_success():...

Full Screen

Full Screen

backend.js

Source:backend.js Github

copy

Full Screen

...24 on_success(parsed,req);25 }26 } else {27 if (on_error) {28 on_error(req);29 }30 }31 };32 req.onerror = function(err) {33 console.log(err,err.target);34 // window._spacedeck_location_change is a flag set by redirect / reload functions35 if (!window._spacedeck_location_change) {36 if (window.spacedeck && window.spacedeck.active_space) {37 window.spacedeck.offline = true;38 } else {39 alert("Could not connect to Spacedeck. Please reconnect and try again.");40 }41 }42 if (on_error) on_error(req);43 }44 req.withCredentials = true;45 req.open(method, api_endpoint+"/api"+path, true);46 if (api_token) {47 req.setRequestHeader("X-Spacedeck-Auth", api_token);48 }49 if (space_auth) {50 req.setRequestHeader("X-Spacedeck-Space-Auth", space_auth);51 }52 if (channel_id) {53 req.setRequestHeader("X-Spacedeck-Channel", channel_id);54 }55 try {56 if (data) {57 if (data.toString() == "[object File]") {58 req.setRequestHeader("Content-type", data.type);59 req.setRequestHeader("Accepts", "application/json");60 req.upload.onprogress = function(e) {61 console.log("upload progress: ",e.loaded,e.total);62 if (on_progress) on_progress(e);63 }64 req.send(data);65 } else {66 req.setRequestHeader("Content-type", "application/json");67 req.send(JSON.stringify(data));68 }69 } else {70 req.send();71 }72 } catch (e) {73 if (on_error) {74 on_error(req, e);75 } else {76 throw(e);77 }78 }79}80function get_resource(path, on_success, on_error, on_progress) {81 load_resource("get", path, null, on_success, on_error, on_progress);82}83function load_profile(name, on_success, on_error) {84 load_resource("get", "/users/slug?slug="+name, null, on_success, on_error);85}86function load_current_user(on_success, on_error) {87 load_resource("get", "/users/current", null, on_success, on_error);88}...

Full Screen

Full Screen

test_observer.py

Source:test_observer.py Github

copy

Full Screen

...5class MyObserver(Observer):6 def on_next(self, value):7 self.has_on_next = value8 9 def on_error(self, err):10 self.has_on_error = err11 def on_completed(self):12 self.has_on_completed = True13def test_to_observer_notification_on_next():14 i = 015 def next(n):16 assert(i == 0)17 assert(n.kind == 'N')18 assert(n.value == 42)19 assert(not hasattr(n, "exception"))20 assert(n.has_value)21 22 Observer.from_notifier(next).on_next(42)23def test_to_observer_notification_on_error():24 ex = 'ex'25 i = 026 def next(n):27 assert(i == 0)28 assert(n.kind == 'E')29 assert(n.exception == ex)30 assert(not n.has_value)31 32 Observer.from_notifier(next).on_error(ex)33def test_to_observer_notification_on_completed():34 i = 035 def next(n):36 assert(i == 0)37 assert(n.kind == 'C')38 assert(not n.has_value)39 Observer.from_notifier(next).on_completed()40def test_to_notifier_forwards():41 obsn = MyObserver()42 obsn.to_notifier()(OnNext(42))43 assert(obsn.has_on_next == 42)44 ex = 'ex'45 obse = MyObserver()46 obse.to_notifier()(OnError(ex))47 assert(ex == obse.has_on_error)48 obsc = MyObserver()49 obsc.to_notifier()(OnCompleted())50 assert(obsc.has_on_completed)51def test_create_on_next():52 next = False53 def on_next(x):54 nonlocal next55 assert(42 == x)56 next = True57 res = Observer(on_next)58 59 res.on_next(42)60 assert(next)61 return res.on_completed()62def test_create_on_next_has_error():63 ex = 'ex'64 next = False65 _e = None66 def on_next(x):67 nonlocal next68 assert(42 == x)69 next = True70 res = Observer(on_next)71 72 res.on_next(42)73 assert(next)74 75 try:76 res.on_error(ex)77 assert(False)78 except Exception as e:79 e_ = e.args[0]80 assert(ex == e_)81def test_create_on_next_on_completed():82 next = False83 completed = False84 def on_next(x):85 nonlocal next86 assert(42 == x)87 next = True88 return next89 def on_completed():90 nonlocal completed91 completed = True92 return completed93 res = Observer(on_next, None, on_completed)94 95 res.on_next(42)96 assert(next)97 assert(not completed)98 res.on_completed()99 assert(completed)100def test_create_on_next_on_completed_has_error():101 e_ = None102 ex = 'ex'103 next = False104 completed = False105 def on_next(x):106 nonlocal next107 assert(42 == x)108 next = True109 def on_completed():110 nonlocal completed111 completed = True112 res = Observer(on_next, None, on_completed)113 114 res.on_next(42)115 assert(next)116 assert(not completed)117 try:118 res.on_error(ex)119 assert(False)120 except Exception as e:121 e_ = e.args[0]122 123 assert(ex == e_)124 assert(not completed)125def test_create_on_next_on_error():126 ex = 'ex'127 next = True128 error = False129 def on_next(x):130 nonlocal next131 assert(42 == x)132 next = True133 134 def on_error(e):135 nonlocal error136 assert(ex == e)137 error = True138 res = Observer(on_next, on_error)139 140 res.on_next(42)141 assert(next)142 assert(not error)143 res.on_error(ex)144 assert(error)145def test_create_on_next_on_error_hit_completed():146 ex = 'ex'147 next = True148 error = False149 150 def on_next(x):151 nonlocal next152 assert(42 == x)153 next = True154 155 def on_error(e):156 nonlocal error157 assert(ex == e)158 error = True159 res = Observer(on_next, on_error)160 res.on_next(42)161 assert(next)162 assert(not error)163 res.on_completed()164 assert(not error)165def test_create_on_next_on_error_on_completed1():166 ex = 'ex'167 next = True168 error = False169 completed = False170 171 def on_next(x):172 nonlocal next173 assert(42 == x)174 next = True175 176 def on_error(e):177 nonlocal error178 assert(ex == e)179 error = True180 def on_completed():181 nonlocal completed182 completed = True183 res = Observer(on_next, on_error, on_completed)184 res.on_next(42)185 assert(next)186 assert(not error)187 assert(not completed)188 res.on_completed()189 assert(completed)190 assert(not error)191def test_create_on_next_on_error_on_completed2():192 ex = 'ex'193 next = True194 error = False195 completed = False196 def on_next(x):197 nonlocal next198 assert(42 == x)199 next = True200 201 def on_error(e):202 nonlocal error203 assert(ex == e)204 error = True205 def on_completed():206 nonlocal completed207 completed = True208 res = Observer(on_next, on_error, on_completed)209 res.on_next(42)210 assert(next)211 assert(not error)212 assert(not completed)213 res.on_error(ex)214 215 assert(not completed)216 assert(error)217def test_as_observer_hides():218 obs = MyObserver()219 res = obs.as_observer()220 221 assert(res != obs)222 assert(not isinstance(res, obs.__class__))223 assert(not isinstance(obs, res.__class__))224def test_as_observer_forwards():225 obsn = MyObserver()226 obsn.as_observer().on_next(42)227 assert(obsn.has_on_next == 42)228 ex = 'ex'229 obse = MyObserver()230 obse.as_observer().on_error(ex)231 assert(obse.has_on_error == ex)232 obsc = MyObserver()233 obsc.as_observer().on_completed()234 assert(obsc.has_on_completed)235def test_observer_checked_already_terminated_completed():236 m, n = 0, 0237 def on_next(x):238 nonlocal m239 m += 1240 def on_error(x):241 assert(False)242 def on_completed():243 nonlocal n244 n += 1245 o = Observer(on_next, on_error, on_completed).checked()246 o.on_next(1)247 o.on_next(2)248 o.on_completed()249 assert_raises(CompletedException, o.on_completed)250 251 try: 252 on.on_error(Exception('error'))253 except Exception:254 pass255 assert(2 == m)256 assert(1 == n)257def test_observer_checked_already_terminated_error():258 m, n = 0, 0259 def on_next(x):260 nonlocal m261 m += 1262 def on_error(x):263 nonlocal n264 n += 1265 def on_completed():266 assert(False)267 o = Observer(on_next, on_error, on_completed).checked()268 o.on_next(1)269 o.on_next(2)270 o.on_error(Exception('error'))271 try:272 o.on_completed()273 except Exception:274 pass275 try: 276 o.on_error(Exception('error'))277 except Exception:278 pass 279 assert(2 == m)280 assert(1 == n)281def test_observer_checked_reentrant_next():282 ex = "Re-entrancy detected"283 n = 0284 def on_next(x):285 nonlocal n286 n += 1287 try:288 o.on_next(9)289 except Exception as e:290 assert str(e) == ex291 try:292 o.on_error(Exception('error'))293 except Exception as e:294 assert str(e) == ex295 try:296 o.on_completed()297 except Exception as e:298 assert str(e) == ex299 def on_error(ex):300 assert(False)301 302 def on_completed():303 assert(False)304 o = Observer(on_next, on_error, on_completed).checked()305 o.on_next(1)306 assert(1 == n)307def test_observer_checked_reentrant_error():308 msg = "Re-entrancy detected"309 n = 0310 311 def on_next(x):312 assert(False)313 314 def on_error(ex):315 nonlocal n316 n += 1317 try:318 o.on_next(9)319 except Exception as e:320 assert str(e) == msg321 try:322 o.on_error(Exception('error'))323 except Exception as e:324 assert str(e) == msg325 try:326 o.on_completed()327 except Exception as e:328 assert str(e) == msg329 def on_completed():330 assert(False)331 o = Observer(on_next, on_error, on_completed).checked()332 o.on_error(Exception('error'))333 assert(1 == n)334def test_observer_checked_reentrant_completed():335 msg = "Re-entrancy detected"336 n = 0337 def on_next(x):338 assert(False)339 def on_error(ex):340 assert(False)341 def on_completed():342 nonlocal n343 n += 1344 try:345 o.on_next(9)346 except Exception as e:347 print (str(e))348 assert str(e) == msg349 try: 350 o.on_error(Exception('error'))351 except Exception as e:352 assert str(e) == msg353 try:354 o.on_completed()355 except Exception as e:356 assert str(e) == msg357 o = Observer(on_next, on_error, on_completed).checked()358 o.on_completed()359 assert(1 == n)360if __name__ == '__main__':...

Full Screen

Full Screen

doaction.py

Source:doaction.py Github

copy

Full Screen

...38 else:39 try:40 on_next(x)41 except Exception as e:42 observer.on_error(e)43 observer.on_next(x)44 def _on_error(exception):45 if not on_error:46 observer.on_error(exception)47 else:48 try:49 on_error(exception)50 except Exception as e:51 observer.on_error(e)52 observer.on_error(exception)53 def _on_completed():54 if not on_completed:55 observer.on_completed()56 else:57 try:58 on_completed()59 except Exception as e:60 observer.on_error(e)61 observer.on_completed()62 return source.subscribe(_on_next, _on_error, _on_completed)63 return AnonymousObservable(subscribe)64@extensionmethod(Observable)65def do_after_next(self, after_next):66 """Invokes an action with each element after it has been emitted downstream.67 This can be helpful for debugging, logging, and other side effects.68 after_next -- Action to invoke on each element after it has been emitted69 """70 def subscribe(observer):71 def on_next(value):72 try:73 observer.on_next(value)74 after_next(value)75 except Exception as e:76 observer.on_error(e)77 return self.subscribe(on_next, observer.on_error, observer.on_completed)78 return AnonymousObservable(subscribe)79@extensionmethod(Observable)80def do_on_subscribe(self, on_subscribe):81 """Invokes an action on subscription.82 This can be helpful for debugging, logging, and other side effects on the start of an operation.83 on_subscribe -- Action to invoke on subscription84 """85 def subscribe(observer):86 on_subscribe()87 return self.subscribe(observer.on_next, observer.on_error, observer.on_completed)88 return AnonymousObservable(subscribe)89@extensionmethod(Observable)90def do_on_dispose(self, on_dispose):91 """Invokes an action on disposal.92 This can be helpful for debugging, logging, and other side effects on the disposal of an operation.93 on_dispose -- Action to invoke on disposal94 """95 class OnDispose(Disposable):96 def dispose(self):97 on_dispose()98 def subscribe(observer):99 composite_disposable = CompositeDisposable()100 composite_disposable.add(OnDispose())101 disposable = self.subscribe(observer.on_next, observer.on_error, observer.on_completed)102 composite_disposable.add(disposable)103 return composite_disposable104 return AnonymousObservable(subscribe)105@extensionmethod(Observable)106def do_on_terminate(self, on_terminate):107 """Invokes an action on an on_complete() or on_error() event.108 This can be helpful for debugging, logging, and other side effects when completion or an error terminates an operation.109 on_terminate -- Action to invoke when on_complete or on_error is called110 """111 def subscribe(observer):112 def on_completed():113 try:114 on_terminate()115 except Exception as err:116 observer.on_error(err)117 else:118 observer.on_completed()119 def on_error(exception):120 try:121 on_terminate()122 except Exception as err:123 observer.on_error(err)124 else:125 observer.on_error(exception)126 return self.subscribe(observer.on_next, on_error, on_completed)127 return AnonymousObservable(subscribe)128@extensionmethod(Observable)129def do_after_terminate(self, after_terminate):130 """Invokes an action after an on_complete() or on_error() event.131 This can be helpful for debugging, logging, and other side effects when completion or an error terminates an operation132 on_terminate -- Action to invoke after on_complete or on_error is called133 """134 def subscribe(observer):135 def on_completed():136 observer.on_completed()137 try:138 after_terminate()139 except Exception as err:140 observer.on_error(err)141 def on_error(exception):142 observer.on_error(exception)143 try:144 after_terminate()145 except Exception as err:146 observer.on_error(err)147 return self.subscribe(observer.on_next, on_error, on_completed)148 return AnonymousObservable(subscribe)149@extensionmethod(Observable)150def do_finally(self, finally_action):151 """Invokes an action after an on_complete(), on_error(), or disposal event occurs152 This can be helpful for debugging, logging, and other side effects when completion, an error, or disposal terminates an operation.153 Note this operator will strive to execute the finally_action once, and prevent any redudant calls154 finally_action -- Action to invoke after on_complete, on_error, or disposal is called155 """156 class OnDispose(Disposable):157 def __init__(self, was_invoked):158 self.was_invoked = was_invoked159 def dispose(self):160 if not self.was_invoked[0]:161 finally_action()162 self.was_invoked[0] = True163 def subscribe(observer):164 was_invoked = [False]165 def on_completed():166 observer.on_completed()167 try:168 if not was_invoked[0]:169 finally_action()170 was_invoked[0] = True171 except Exception as err:172 observer.on_error(err)173 def on_error(exception):174 observer.on_error(exception)175 try:176 if not was_invoked[0]:177 finally_action()178 was_invoked[0] = True179 except Exception as err:180 observer.on_error(err)181 composite_disposable = CompositeDisposable()182 composite_disposable.add(OnDispose(was_invoked))183 disposable = self.subscribe(observer.on_next, on_error, on_completed)184 composite_disposable.add(disposable)185 return composite_disposable...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1wpt.on_error = function(msg) {2 console.log(msg);3}4wpt.on_log = function(msg) {5 console.log(msg);6}7wpt.on_result = function(msg) {8 console.log(msg);9}10wpt.on_status = function(msg) {11 console.log(msg);12}13wpt.on_video = function(msg) {14 console.log(msg);15}16wpt.on_data = function(msg) {17 console.log(msg);18}19wpt.on_test_complete = function(msg) {20 console.log(msg);21}22wpt.on_test_complete = function(msg) {23 console.log(msg);24}25wpt.on_test_complete = function(msg) {26 console.log(msg);27}28wpt.on_test_complete = function(msg) {29 console.log(msg);30}31wpt.on_test_complete = function(msg) {32 console.log(msg);33}34wpt.on_test_complete = function(msg) {35 console.log(msg);36}37wpt.on_test_complete = function(msg) {38 console.log(msg);39}40wpt.on_test_complete = function(msg) {41 console.log(msg);42}43wpt.on_test_complete = function(msg) {44 console.log(msg);45}

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890abcdef1234567890abcdef12345678');3wpt.on_error = function(err) {4 console.log("Error: " + err);5}6 if (err) {7 console.log("Error: " + err);8 } else {9 console.log(data);10 }11});12var WebPageTest = require('webpagetest');13var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890abcdef1234567890abcdef12345678');14wpt.on_error = function(err) {15 console.log("Error: " + err);16}17 if (err) {18 console.log("Error: " + err);19 } else {20 console.log(data);21 }22});23var wpt = require('webpagetest');24var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890abcdef1234567890abcdef12345678');25wpt.on_error = function(err) {26 console.log("Error: " + err);27}28 if (err) {29 console.log("Error: " + err);30 } else {31 console.log(data);32 }33});34var WebPageTest = require('webpagetest');35var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890abcdef1234567890abcdef12345678');36wpt.on_error = function(err) {37 console.log("Error: " + err);38}39 if (err) {40 console.log("Error: " + err);41 } else {42 console.log(data);43 }44});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.on_error = function(err) {4 console.log("Error: " + err);5};6 if (err) {7 console.log("Error: " + err);8 } else {9 console.log("Test Results: " + data);10 }11});12var wpt = require('webpagetest');13var wpt = new WebPageTest('www.webpagetest.org');14wpt.on_error = function(err) {15 console.log("Error: " + err);16};17 if (err) {18 console.log("Error: " + err);19 } else {20 console.log("Test Results: " + data);21 }22});23var wpt = require('webpagetest');24var wpt = new WebPageTest('www.webpagetest.org');25wpt.on_error = function(err) {26 console.log("Error: " + err);27};28 if (err) {29 console.log("Error: " + err);30 } else {31 console.log("Test Results: " + data);32 }33});34var wpt = require('webpagetest');35var wpt = new WebPageTest('www.webpagetest.org');36wpt.on_error = function(err) {37 console.log("Error: " + err);38};39 if (err) {40 console.log("Error: " + err);41 } else {42 console.log("Test Results: " + data);43 }44});45var wpt = require('webpagetest');46var wpt = new WebPageTest('www.webpagetest.org');47wpt.on_error = function(err) {48 console.log("Error: "

Full Screen

Using AI Code Generation

copy

Full Screen

1const wpt = require('webpagetest');2const test = new wpt('API_KEY');3 if (err) {4 console.log(err);5 } else {6 console.log(data);7 }8});9 if (err) {10 console.log(err);11 } else {12 console.log(data);13 }14}).on('error', (err) => {15 console.log('error', err);16});17 if (err) {18 console.log(err);19 } else {20 console.log(data);21 }22}).on('error', (err) => {23 console.log('error', err);24});25 if (err) {26 console.log(err);27 } else {28 console.log(data);29 }30}).on('error', (err) => {31 console.log('error', err);32});33 if (err) {34 console.log(err);35 } else {36 console.log(data);37 }38}).on('error', (err) => {39 console.log('error', err);40});41 if (err) {42 console.log(err);43 } else {44 console.log(data);45 }46}).on('error', (err) => {47 console.log('error', err);48});49 if (err) {50 console.log(err);51 } else {52 console.log(data);53 }54}).on('error', (err) => {55 console.log('error', err);56});57test.runTest('https

Full Screen

Using AI Code Generation

copy

Full Screen

1 if (err) {2 console.log(err);3 } else {4 console.log(data);5 }6});71. Fork it (

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var webpagetest = new wpt('www.webpagetest.org', 'A.2e8c4f4e1d4c4b4a4b4d4c4a4b4a4e4');3 console.log(data);4 if (err) {5 console.log(err);6 } else {7 console.log(data);8 }9});10var wpt = require('webpagetest');11var webpagetest = new wpt('www.webpagetest.org', 'A.2e8c4f4e1d4c4b4a4b4d4c4a4b4a4e4');12 console.log(data);13 if (err) {14 console.log(err);15 } else {16 console.log(data);17 }18});19var wpt = require('webpagetest');20var webpagetest = new wpt('www.webpagetest.org', 'A.2e8c4f4e1d4c4b4a4b4d4c4a4b4a4e4');21 console.log(data);22 if (err) {23 console.log(err);24 } else {25 console.log(data);26 }27});28var wpt = require('webpagetest');29var webpagetest = new wpt('www.webpagetest.org', 'A.2e8c4f4e1d4c4b4a4b4d4c4a4b4a4e4');30 console.log(data);31 if (err) {32 console.log(err);

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful