class CustomErrors
Public Instance Methods
on_complete(env)
click to toggle source
# File lib/veyor/request.rb, line 8 def on_complete(env) case env[:status] when 400 raise Veyor::BadRequest, error_message_400(env) when 404 raise Veyor::NotFound, error_message_400(env) when 500 raise Veyor::InternalServerError, error_message_500(env, "Something is technically wrong.") when 502 raise Veyor::BadGateway, error_message_500(env, "The server returned an invalid or incomplete response.") when 503 raise Veyor::ServiceUnavailable, error_message_500(env, "Appveyor is rate limiting your requests.") when 504 raise Veyor::GatewayTimeout, error_message_500(env, "504 Gateway Time-out") end end
Private Instance Methods
error_body(body)
click to toggle source
# File lib/veyor/request.rb, line 31 def error_body(body) if not body.nil? and not body.empty? and body.kind_of?(String) if is_json?(body) body = ::MultiJson.load(body) if body['message'].nil? body = nil else body = body['message'] end end end if body.nil? nil else ": #{body}" end end
error_message_400(x)
click to toggle source
# File lib/veyor/request.rb, line 27 def error_message_400(x) "\n #{x.method.to_s.upcase} #{x.url.to_s}\n Status #{x.status}#{error_body(x.body)}" end
error_message_500(x, body=nil)
click to toggle source
# File lib/veyor/request.rb, line 50 def error_message_500(x, body=nil) "\n #{x.method.to_s.upcase} #{x.url.to_s}\n Status #{[x.status.to_s + ':', body].compact.join(' ')}" end
is_json?(string)
click to toggle source
# File lib/veyor/request.rb, line 54 def is_json?(string) MultiJson.load(string) return true rescue MultiJson::ParseError => e return false end