Skip to content

Instantly share code, notes, and snippets.

@mactkg
Last active January 30, 2016 10:02
Show Gist options
  • Save mactkg/c9c6a04807e3b1e11876 to your computer and use it in GitHub Desktop.
Save mactkg/c9c6a04807e3b1e11876 to your computer and use it in GitHub Desktop.
You can use this feature at this branch: https://github.com/mactkg/Gyazo/tree/good-fail
diff --git a/script.original b/script
index e46e48f..2d76e3a 100644
--- a/script.original
+++ b/script
@@ -4,6 +4,13 @@
require 'net/http'
require 'net/https' # for ruby 1.8.x
+def save_img(imgdata, filename=nil)
+ filename ||= "#{ENV['HOME']}/Desktop/Gyazo failed to upload at #{Time.now.to_s}.png"
+ File.open(filename, "w") do |file|
+ file.puts(imgdata)
+ end
+end
+
begin
require 'json'
rescue LoadError
@@ -208,10 +215,12 @@ begin
@res = http.post(CGI, data, header)
end
rescue => e
+ save_img imagedata
abort("Failed to upload.\n#{e}")
end
if @res.code.to_i >= 400
+ save_img imagedata
abort("Failed to upload.\n#{@res.code}: #{@res.message}")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment