Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/reel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions lib/reel/request/multipart.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -67,8 +67,8 @@ def decode
begin
@body.each { |chunks| write chunks }
rescue => e
warn e
@files = {}
raise e
end
@files
end
Expand Down
10 changes: 6 additions & 4 deletions spec/reel/multipart_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down