<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -115,7 +115,12 @@ class APICache
           cache.get
         else
           APICache.logger.warn &quot;Data not available in the cache or from API for key #{@key}&quot;
-          raise e
+          if options.has_key?(:fail)
+            fail = options[:fail]
+            fail.respond_to?(:call) ? fail.call : fail
+          else
+            raise e
+          end
         end
       end
     end</diff>
      <filename>lib/api_cache.rb</filename>
    </modified>
    <modified>
      <diff>@@ -52,4 +52,22 @@ describe &quot;api_cache&quot; do
       end
     }.should_not raise_error
   end
+
+  it &quot;should return a default value rather than raising an exception if :fail passed&quot; do
+    APICache.get('foo', :fail =&gt; &quot;bar&quot;) do
+      raise 'foo'
+    end.should == 'bar'
+  end
+
+  it &quot;should accept a proc to fail&quot; do
+    APICache.get('foo', :fail =&gt; lambda { &quot;bar&quot; }) do
+      raise 'foo'
+    end.should == 'bar'
+  end
+
+  it &quot;should accept nil values for :fail&quot; do
+    APICache.get('foo', :fail =&gt; nil) do
+      raise 'foo'
+    end.should == nil
+  end
 end</diff>
      <filename>spec/integration_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>102804e1df5e879dd64b77040e3390048dadbcb1</id>
    </parent>
  </parents>
  <author>
    <name>Martyn Loughran</name>
    <email>me@mloughran.com</email>
  </author>
  <url>http://github.com/mloughran/api_cache/commit/2a351cce1938dbab0cc98e8d9038011388c26c87</url>
  <id>2a351cce1938dbab0cc98e8d9038011388c26c87</id>
  <committed-date>2009-08-20T17:55:30-07:00</committed-date>
  <authored-date>2009-08-20T17:50:34-07:00</authored-date>
  <message>Support the :fail parameter - cleaner than catching exceptions in simple cases</message>
  <tree>428ca87fc57977fa1aed89a52f42f994e1d52ea8</tree>
  <committer>
    <name>Martyn Loughran</name>
    <email>me@mloughran.com</email>
  </committer>
</commit>
