summaryrefslogtreecommitdiff
path: root/users/app/models/token.rb
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2014-04-04 11:48:24 +0200
committerAzul <azul@leap.se>2014-04-04 11:48:50 +0200
commit85aabe832eb3eec10a29054ef5575618686eef33 (patch)
tree38492b2bd598bcc7cca1c111201382b2ede23259 /users/app/models/token.rb
parent7b4f9ad334ec702449fdc683ea8fc312e06b2bd9 (diff)
5382 - prevent crash when destroying tokens
An expired token was removed (probably by automatic cleanup) while processing it. So the webapp crashed due to a couch 404. We're preventing that by rescueing from a 404 on Token.delete by default.
Diffstat (limited to 'users/app/models/token.rb')
-rw-r--r--users/app/models/token.rb8
1 files changed, 8 insertions, 0 deletions
diff --git a/users/app/models/token.rb b/users/app/models/token.rb
index 001eb40..4856c31 100644
--- a/users/app/models/token.rb
+++ b/users/app/models/token.rb
@@ -40,6 +40,14 @@ class Token < CouchRest::Model::Base
end
end
+ # Tokens can be cleaned up in different ways.
+ # So let's make sure we don't crash if they disappeared
+ def destroy_with_rescue
+ destroy_without_rescue
+ rescue RestClient::ResourceNotFound
+ end
+ alias_method_chain :destroy, :rescue
+
def touch
self.last_seen_at = Time.now
save