diff --git a/lib/reel.rb b/lib/reel.rb index ea0af18..83626a5 100644 --- a/lib/reel.rb +++ b/lib/reel.rb @@ -42,4 +42,12 @@ class UnsupportedMethodError < ArgumentError; end # wrong state for a given operation class StateError < RuntimeError; end + # Multipart Parsing Error + # :error_code paramter can be used for responding purpose + class MultipartParseError < RequestError + def initialize error_code + @error_code = error_code + end + attr_reader :error_code + end end diff --git a/lib/reel/request/multipart.rb b/lib/reel/request/multipart.rb index 3a459e3..e8baa8d 100644 --- a/lib/reel/request/multipart.rb +++ b/lib/reel/request/multipart.rb @@ -54,8 +54,8 @@ def initialize(body, boundary) #TODO : expose part information if needed } end - - @reader.on_error{|msg| warn msg } + # Raising MultipartParseError with error code 400 + @reader.on_error{|msg| raise MultipartParseError.new(400), msg } end @@ -67,8 +67,8 @@ def decode begin @body.each { |chunks| write chunks } rescue => e - warn e @files = {} + raise e end @files end diff --git a/spec/reel/multipart_spec.rb b/spec/reel/multipart_spec.rb index c522649..3d4a40a 100644 --- a/spec/reel/multipart_spec.rb +++ b/spec/reel/multipart_spec.rb @@ -146,15 +146,17 @@ raise ex if ex end - it "Parsing error for wrong boundary value" do + it "MultipartParseError for wrong boundary value" do ex = nil handler = proc do |connection| begin req = connection.request - expect(req.multipart? req.body).to eq true - expect(req.multipart.empty?).to eq true - + begin + req.multipart + rescue => e + expect(e.is_a? Reel::MultipartParseError).to eq true + end req.respond :ok, response_body rescue => ex end