pusher/pusher-http-ruby

Handling payload bigger than 10KB

yarcub opened this issue ยท 1 comments

Hi ๐Ÿ‘‹

I'm trying to handle failure calls to trigger due to message exceeding 10KB. From my understanding REST API will respond with a 413 HTTP status code but this library doesn't expose it.

  1. the status is not exposed on the trigger returned value
  2. neither as a specific error

def handle_response(status_code, body)
case status_code
when 200
return symbolize_first_level(MultiJson.decode(body))
when 202
return body.empty? ? true : symbolize_first_level(MultiJson.decode(body))
when 400
raise Error, "Bad request: #{body}"
when 401
raise AuthenticationError, body
when 404
raise Error, "404 Not found (#{@uri.path})"
when 407
raise Error, "Proxy Authentication Required"
else
raise Error, "Unknown error (status code #{status_code}): #{body}"
end
end

It raises an unknown error with the message Unknown error (status code 413): #{body}

Imo, it's a know error (payload too big) and now the only way we can correctly handle/report it is by checking if the message for (status code 413) which seems far from ideal.

What are you thoughts on this? Should it raise a more specific error?

Iโ€™m really sorry for such a delay in getting back to you and thanks for submitting an issue. This issue was fixed in the latest versions of the library: https://github.com/pusher/pusher-http-ruby/blob/master/lib/pusher/request.rb#L83-L100, therefore Iโ€™m going to close it.