<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -47,13 +47,23 @@ class FlickrPhoto &lt; ActiveRecord::Base
   
   # Creates or updates and image in an event for the given flickr ID.
   def self.create_or_update_image(event, flickrid, license_hash=nil)
+    logger.info &quot;Updating image #{flickrid} in event #{event.name}&quot;
     # load the image, or create a new one
     fp = FlickrPhoto.find_by_flickrid(flickrid)
     unless fp
       fp = FlickrPhoto.new
       fp.flickrid = flickrid
     end
-    response = FlickrPhoto.request(&quot;flickr.photos.getInfo&quot;, &quot;photo_id&quot; =&gt; flickrid.to_s)
+    begin
+      response = FlickrPhoto.request(&quot;flickr.photos.getInfo&quot;, 
+                  &quot;photo_id&quot; =&gt; flickrid.to_s)
+    rescue FlickrAPIError =&gt; e
+      if e.code == FlickrAPIError::INVALID_ID
+        logger.info &quot;Image with flickr id #{flickrid} gone - deleting&quot;
+        fp.destroy
+      end
+      return # regardless, as no updating will happen now.
+    end
     
     # check the tag list for a matching event tag - if it doesn't exist, remove and return
     event_tag_found = false
@@ -165,10 +175,26 @@ class FlickrPhoto &lt; ActiveRecord::Base
     if response.root.attributes[&quot;stat&quot;] == &quot;ok&quot; then
       return response
     elsif response.root.attributes[&quot;stat&quot;] == &quot;fail&quot; then
-      raise &quot;Flickr API error #{response.elements[&quot;rsp/err&quot;].attributes[&quot;code&quot;]}: #{response.elements[&quot;rsp/err&quot;].attributes[&quot;msg&quot;]}&quot;
+      raise FlickrAPIError.new(
+          response.elements[&quot;rsp/err&quot;].attributes[&quot;code&quot;].to_i,
+          response.elements[&quot;rsp/err&quot;].attributes[&quot;msg&quot;])
     else
       raise &quot;Request status neither ok nor fail. Tried to fetch #{call_uri}.&quot;
     end
   end
   
 end
+
+# Our new custom exception class
+class  FlickrAPIError &lt; RuntimeError
+  attr_reader :code, :message
+  
+  INVALID_ID = 1
+  API_NOT_AVAILABLE = 0
+  
+  def initialize(code, message)
+    super(&quot;Flickr API error #{code}: #{message}&quot;)
+    @code = code
+    @message = @message
+  end
+end</diff>
      <filename>app/models/flickr_photo.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>557a66a0243a3e6009cebe756d7d3ca52e0a571a</id>
    </parent>
  </parents>
  <author>
    <name>Lincoln Stoll</name>
    <email>lstoll@lstoll.net</email>
  </author>
  <url>http://github.com/webjam/webjam/commit/801f90ceecf73ea03545942c7c6e4e4729e73fca</url>
  <id>801f90ceecf73ea03545942c7c6e4e4729e73fca</id>
  <committed-date>2009-10-07T10:17:46-07:00</committed-date>
  <authored-date>2009-10-07T10:17:46-07:00</authored-date>
  <message>Better error handling, and remove images from our DB if they have been removed from flickr. Closes #12</message>
  <tree>e97ce68a08fd572e45374f2f2780026d8d5eb088</tree>
  <committer>
    <name>Lincoln Stoll</name>
    <email>lstoll@lstoll.net</email>
  </committer>
</commit>
