Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Better capistrano error handling #7

Merged
merged 2 commits into from

2 participants

@anttipitkanen

Even better error handling for capistrano task, and also for non-successful responses from the API.

@livedo livedo merged commit df62fd6 into master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 9, 2012
  1. Working deployment error messages

    Antti Pitkanen authored
  2. More sensible handling of error responses from API

    Antti Pitkanen authored
This page is out of date. Refresh to see the latest.
Showing with 10 additions and 10 deletions.
  1. +6 −6 lib/flowdock.rb
  2. +4 −4 lib/flowdock/capistrano.rb
View
12 lib/flowdock.rb
@@ -13,7 +13,7 @@ class ApiError < StandardError; end
def initialize(options = {})
@api_token = options[:api_token]
raise InvalidParameterError, "Flow must have :api_token attribute" if blank?(@api_token)
-
+
@source = options[:source]
raise InvalidParameterError, "Flow must have valid :source attribute, only alphanumeric characters and underscores can be used" if blank?(@source) || !@source.match(/^[a-z0-9\-_ ]+$/i)
@@ -25,13 +25,13 @@ def initialize(options = {})
def send_message(params)
raise InvalidParameterError, "Message must have both :subject and :content" if blank?(params[:subject]) || blank?(params[:content])
-
+
from = (params[:from].kind_of?(Hash)) ? params[:from] : @from
raise InvalidParameterError, "Flow's :from attribute must have :address attribute" if blank?(from[:address])
tags = (params[:tags].kind_of?(Array)) ? params[:tags] : []
tags.reject! { |tag| !tag.kind_of?(String) || blank?(tag) }
-
+
link = (!blank?(params[:link])) ? params[:link] : nil
params = {
@@ -48,16 +48,16 @@ def send_message(params)
# Send the request
resp = self.class.post(get_flowdock_api_url, :body => params)
- raise ApiError, (resp.code == 500 ? "Flowdock API returned error: #{resp.body}" : "HTTP Error #{resp.code}") unless resp.code == 200
+ raise ApiError, "Flowdock API returned error: Status: #{resp.code} Body: #{resp.body}" unless resp.code == 200
true
end
-
+
private
def blank?(var)
var.nil? || var.respond_to?(:length) && var.length == 0
end
-
+
def get_flowdock_api_url
"#{FLOWDOCK_API_URL}/#{@api_token}"
end
View
8 lib/flowdock/capistrano.rb
@@ -15,7 +15,7 @@
begin
run "echo '#{source.head}' > #{current_path}/BRANCH"
rescue => e
- puts "Flowdock: error in saving deployed branch information: " + e
+ puts "Flowdock: error in saving deployed branch information: #{e.to_s}"
end
end
@@ -25,7 +25,7 @@
set :repo, Grit::Repo.new(".")
config = Grit::Config.new(repo)
rescue => e
- puts "Flowdock: error in fetching your git repository information: " + e
+ puts "Flowdock: error in fetching your git repository information: #{e.to_s}"
end
begin
@@ -33,7 +33,7 @@
:source => "Capistrano deployment", :project => flowdock_project_name,
:from => {:name => config["user.name"], :address => config["user.email"]})
rescue => e
- puts "Flowdock: error in configuring Flowdock API: " + e
+ puts "Flowdock: error in configuring Flowdock API: #{e.to_s}"
end
end
@@ -45,7 +45,7 @@
:content => notification_message,
:tags => ["deploy", "#{rails_env}"] | flowdock_deploy_tags)
rescue => e
- puts "Flowdock: error in sending notification to your flow: " + e
+ puts "Flowdock: error in sending notification to your flow: #{e.to_s}"
end
end
Something went wrong with that request. Please try again.