pubnub 3.3.0.5 → 3.3.0.6

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of pubnub might be problematic. Click here for more details.

Files changed (2) hide show
  1. data/lib/pubnub.rb +35 -9
  2. metadata +1 -1
data/lib/pubnub.rb CHANGED
@@ -29,6 +29,7 @@ require 'active_support/core_ext/object/blank'
29
29
  class Pubnub
30
30
 
31
31
  SUCCESS_RESPONSE = 200
32
+ MSG_TOO_LARGE_RESPONSE = 400
32
33
 
33
34
  TIMEOUT_BAD_RESPONSE_CODE = 1
34
35
  TIMEOUT_BAD_JSON_RESPONSE = 0.5
@@ -292,11 +293,30 @@ class Pubnub
292
293
  }
293
294
 
294
295
  req.callback {
295
- if checkForBadJSON(req) == true
296
- logAndRetryBadJSON(is_reactor_running, req, request)
296
+
297
+ if %w(subscribe presence).include?(request.operation)
298
+ if (checkForBadJSON(req) == true && request.operation == "subscribe")
299
+ logAndRetryBadJSON(is_reactor_running, req, request)
300
+ else
301
+ processGoodResponse(is_reactor_running, req, request)
302
+ end
297
303
  else
298
- processGoodResponse(is_reactor_running, req, request)
304
+ if req.response_header.http_status.to_i != SUCCESS_RESPONSE
305
+
306
+ begin
307
+ server_response = Yajl.load(req.response)
308
+ request.callback.call(server_response)
309
+ rescue => e
310
+ request.callback.call([0, "Bad server response: #{req.response_header.http_status.to_i}"])
311
+ ensure
312
+ EM.stop unless is_reactor_running
313
+ end
314
+
315
+ else
316
+ processGoodResponse(is_reactor_running, req, request)
317
+ end
299
318
  end
319
+
300
320
  }
301
321
 
302
322
  rescue EventMachine::ConnectionError, RuntimeError => e # RuntimeError for catching "EventMachine not initialized"
@@ -320,7 +340,11 @@ class Pubnub
320
340
  def processGoodResponse(is_reactor_running, req, request)
321
341
 
322
342
  if (req.response_header.http_status.to_i != SUCCESS_RESPONSE)
323
- logAndRetryBadResponseCode(is_reactor_running, req, request)
343
+
344
+ unless (req.response_header.http_status.to_i == MSG_TOO_LARGE_RESPONSE)
345
+ logAndRetryBadResponseCode(is_reactor_running, req, request)
346
+ end
347
+
324
348
  else
325
349
 
326
350
  request.package_response!(req.response)
@@ -336,24 +360,26 @@ class Pubnub
336
360
 
337
361
  def logAndRetryGeneralError(is_reactor_running, req, request)
338
362
  errMsg = "#{Time.now}: Network connectivity issue while attempting to reach #{request.url}"
339
- logError(errMsg)
363
+ logError(errMsg, request.url)
340
364
  retryRequest(is_reactor_running, req, request, TIMEOUT_GENERAL_ERROR)
341
365
  end
342
366
 
343
367
  def logAndRetryBadJSON(is_reactor_running, req, request)
344
368
  errMsg = "#{Time.now}: Retrying from bad JSON: #{req.response.to_s}"
345
- logError(errMsg)
369
+ logError(errMsg, request.url)
346
370
  retryRequest(is_reactor_running, req, request, TIMEOUT_BAD_JSON_RESPONSE)
347
371
  end
348
372
 
349
373
  def logAndRetryBadResponseCode(is_reactor_running, req, request)
350
374
  errMsg = "#{Time.now}: Retrying from bad server response code: (#{req.response_header.http_status.to_i}) #{req.response.to_s}"
351
- logError(errMsg)
375
+ logError(errMsg, request.url)
352
376
  retryRequest(is_reactor_running, req, request, TIMEOUT_BAD_RESPONSE_CODE)
353
377
  end
354
378
 
355
- def logError(errMsg)
356
- PUBNUB_LOGGER.debug(errMsg)
379
+ def logError(errMsg, url)
380
+ PUBNUB_LOGGER.debug("url: #{url}")
381
+ PUBNUB_LOGGER.debug("#{errMsg}")
382
+ PUBNUB_LOGGER.debug("")
357
383
  end
358
384
 
359
385
  def retryRequest(is_reactor_running, req, request, delay)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pubnub
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.0.5
4
+ version: 3.3.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: