datastar 1.0.5 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3e8680c34cae9941df0cdd31d0bcb04e44d3d402b4ac552b56ab0cb62d510628
4
- data.tar.gz: 5b2bb1404549cfeaab4e9ad2dff1a53b67ac6bd4adc86f1cb52c3b7591229b7e
3
+ metadata.gz: 6fc6011ed2e49835f82ef6345c457f7e50812d155802ca722a9abb7858bffcc6
4
+ data.tar.gz: 6849ec8942f01e3d252e2bfdc77902bb4901663a2baa153fd72e421b64336915
5
5
  SHA512:
6
- metadata.gz: 919a990d068032292269cbdb3eed058e78f72680786fb9db8ba250da387007e31c33918d96f50201fcf7b75169f2e8ab84bb880daa66e56702289371d0854d68
7
- data.tar.gz: 878e3330cd5ddf62e89322c7e1564c20fc9855edf49b4018556947bc1efc91d93594cd67396f56f5c945f2b143214dd7ade43c69cd1bb5665ae50f58b2e22698
6
+ metadata.gz: 895e948c8ea3cb095768c409fc6fcb9cec2d31c20fa41c47ac0131af35729aeb8ee0138d880cd70e9ec06d893101791e8a1d5db73355496f69bbe0242e9a03f1
7
+ data.tar.gz: f7f10819510f6b69757b2982cf71bbe31a8504688e5efd575cc077a97e183e17f16b5d10a830bcb8966eec4076cfac2bcb2faddc74b355288cb6ec8d21dd97d4
@@ -386,14 +386,33 @@ module Datastar
386
386
  @compressor.wrap_socket(socket)
387
387
  end
388
388
 
389
+ # Errors raised when writing to a socket the client has closed.
390
+ DISCONNECT_ERRORS = [IOError, Errno::EPIPE, Errno::ECONNRESET].freeze
391
+
392
+ # Whether an error means the client went away.
393
+ #
394
+ # Servers may wrap the underlying socket error in their own class
395
+ # (e.g. protocol-http1 >= 0.41 raises +Protocol::HTTP::RemoteError+
396
+ # from a +rescue Errno::EPIPE+), so the +cause+ chain is checked too.
397
+ #
398
+ # @param error [Exception]
399
+ # @return [Boolean]
400
+ def client_disconnect?(error)
401
+ while error
402
+ return true if DISCONNECT_ERRORS.any? { |klass| error.is_a?(klass) }
403
+
404
+ error = error.cause
405
+ end
406
+ false
407
+ end
408
+
389
409
  # Handle errors caught during streaming
390
410
  # @param error [Exception] the error that occurred
391
411
  # @param socket [IO] the socket to pass to error handlers
392
412
  def handle_streaming_error(error, socket)
393
- case error
394
- when IOError, Errno::EPIPE, Errno::ECONNRESET
413
+ if client_disconnect?(error)
395
414
  @on_client_disconnect.each { |callable| callable.call(socket) }
396
- when Exception
415
+ else
397
416
  @on_error.each { |callable| callable.call(error) }
398
417
  end
399
418
  end
@@ -407,10 +426,8 @@ module Datastar
407
426
  yield
408
427
 
409
428
  @on_server_disconnect.each { |callable| callable.call(generator) }
410
- rescue IOError, Errno::EPIPE, Errno::ECONNRESET => e
411
- @on_client_disconnect.each { |callable| callable.call(socket) }
412
429
  rescue Exception => e
413
- @on_error.each { |callable| callable.call(e) }
430
+ handle_streaming_error(e, socket)
414
431
  end
415
432
 
416
433
  # Parse signals from the request
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Datastar
4
- VERSION = '1.0.5'
4
+ VERSION = '1.0.6'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datastar
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ismael Celis