pengwynn/faraday_middleware — Issue #21: Error while using Caching middleware
Author: sosedoff
Created: 2012-02-24 00:20:31+00:00
State: open

Found an error while creating a cache for API client. Not sure if its due to improper usage or just a bug:

```
/Users/sosedoff/.rvm/gems/ruby-1.9.2-p290/gems/faraday_middleware-0.8.4/lib/faraday_middleware/response/caching.rb:74:in `finalize_response': undefined method `env' for nil:NilClass (NoMethodError)
from /Users/sosedoff/.rvm/gems/ruby-1.9.2-p290/gems/faraday_middleware-0.8.4/lib/faraday_middleware/response/caching.rb:38:in `call'
from /Users/sosedoff/.rvm/gems/ruby-1.9.2-p290/gems/faraday-0.7.6/lib/faraday/connection.rb:210:in `run_request'
from /Users/sosedoff/.rvm/gems/ruby-1.9.2-p290/gems/faraday-0.7.6/lib/faraday/connection.rb:93:in `get'

```

Usage:

```ruby
module TestApp
module Cache
def self.fetch(key)
nil
end

def self.read(key)
nil
end

def self.write(key, value)
puts "#{key} => #{value}"
end
end
end

def connection(url)
connection = Faraday.new(url) do |c|
c.use(Faraday::Request::Multipart)
c.use(Faraday::Request::UrlEncoded)
c.use(Faraday::Response::ParseJson)
c.use(FaradayMiddleware::Caching, TestApp::Cache, :ignore_params => [:api_token])
c.use(Faraday::Response::Logger)
c.adapter(Faraday.default_adapter)
end
end
```

Any idea why this is happening ?