Skip to content

Commit d62aa85

Browse files
committed
Refactor request.rb to handling HTTP 413
This commit refactors the /lib/pusher/request.rb to handling HTTP 413 payload bigger than 10kb. Today, when this error occurs, will raise an unknown error this does not make sense because that error is known by the library and I think the library should raise the specific error.
1 parent 86e613f commit d62aa85

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

lib/pusher/request.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ def handle_response(status_code, body)
9494
raise Error, "404 Not found (#{@uri.path})"
9595
when 407
9696
raise Error, "Proxy Authentication Required"
97+
when 413
98+
raise Error, "Payload Too Large > 10KB"
9799
else
98100
raise Error, "Unknown error (status code #{status_code}): #{body}"
99101
end

spec/client_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,11 @@
430430
expect { call_api }.to raise_error(Pusher::Error, 'Proxy Authentication Required')
431431
end
432432

433+
it "should raise Pusher::Error if pusher returns 413" do
434+
stub_request(verb, @url_regexp).to_return({:status => 413})
435+
expect { call_api }.to raise_error(Pusher::Error, 'Payload Too Large > 10KB')
436+
end
437+
433438
it "should raise Pusher::Error if pusher returns 500" do
434439
stub_request(verb, @url_regexp).to_return({:status => 500, :body => "some error"})
435440
expect { call_api }.to raise_error(Pusher::Error, 'Unknown error (status code 500): some error')

0 commit comments

Comments
 (0)