Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a anything_else option to callbacks that is run if a response code other than the ones listed is returned #117

Open
kaiwren opened this issue Aug 7, 2015 · 0 comments

Comments

@kaiwren
Copy link
Contributor

kaiwren commented Aug 7, 2015

"http://google.com".to_uri.get do |callback|
    callback.on_ok do |response|
      Wrest.logger.info "Ok."
    end

    callback.on(202) do |response|
      Wrest.logger.info "Accepted."
    end

    callback.on(200..206) do |response|
      Wrest.logger.info "Successful."
    end

    callback.anything_else do |response|
      Wrest.logger.info "An unexpected response code was received"
    end
  end

 "http://google.com".to_uri(:callback => {
      200      => lambda {|response| Wrest.logger.info "Ok." },
      400..499 => lambda {|response| Wrest.logger.error "Invalid. #{response.body}"},
      300..302 => lambda {|response| Wrest.logger.debug "Redirected. #{response.message}" }
      :anything_else => lambda {|response| Wrest.logger.debug "Unexpected response code. #{response.message}" }
  }).get
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant