Skip to content

Commit

Permalink
Handling nonexistent destination user
Browse files Browse the repository at this point in the history
  • Loading branch information
vindimy committed Dec 3, 2013
1 parent 7f8c517 commit b845573
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/ctb/ctb_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,13 @@ def validate(self, is_pending=False):
self.save('failed')
return False

if self.u_to and not self.u_to.is_on_reddit():
msg = self.ctb.jenv.get_template('not-on-reddit.tpl').render(a=self, ctb=self.ctb)
lg.debug("CtbAction::validate(): %s", msg)
self.u_from.tell(subj="+tip failed", msg=msg)
self.save('failed')
return False

# Verify that coin type is set
if not self.coin:
msg = self.ctb.jenv.get_template('no-coin-balances.tpl').render(a=self, ctb=self.ctb)
Expand Down
3 changes: 3 additions & 0 deletions src/ctb/ctb_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ def praw_call(prawFunc, *extraArgs, **extraKwArgs):
if str(e) == "403 Client Error: Forbidden":
lg.warning("praw_call(): 403 forbidden")
return False
if str(e) == "404 Client Error: Not Found":
lg.warning("praw_call(): 404 not found")
return False
lg.warning("praw_call(): Reddit is down (%s), sleeping...", e)
time.sleep(30)
pass
Expand Down
2 changes: 2 additions & 0 deletions src/ctb/ctb_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ def is_on_reddit(self):
self.prawobj = ctb_misc.praw_call(self.ctb.reddit.get_redditor, self.name)
if self.prawobj:
return True
else:
return False

except Exception as e:
lg.debug("< CtbUser::is_on_reddit(%s) DONE (no)", self.name)
Expand Down
5 changes: 5 additions & 0 deletions src/tpl/jinja2/not-on-reddit.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% set user_from = a.u_from.name %}
{% set user_to = a.u_to.name %}
I'm sorry {{ user_from | replace('_', '\_') }}, your tip has failed because user **{{ user_to | replace('_', '\_') }}** is not on Reddit.

{% include 'footer.tpl' %}

0 comments on commit b845573

Please sign in to comment.