Skip to content

Commit

Permalink
Improve error handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed May 8, 2019
1 parent 67d1597 commit b46f571
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
32 changes: 30 additions & 2 deletions lib/protocol/websocket/error.rb
Expand Up @@ -22,10 +22,38 @@

module Protocol
module WebSocket
class BadRequest < HTTP::BadRequest
# Status codes as defined by <https://tools.ietf.org/html/rfc6455#section-7.4.1>.
class Error < HTTP::Error
# Indicates a normal closure, meaning that the purpose for which the connection was established has been fulfilled.
NO_ERROR = 1000

# Indicates that an endpoint is "going away", such as a server going down or a browser having navigated away from a page.
GOING_AWAY = 1001

# Indicates that an endpoint is terminating the connection due to a protocol error.
PROTOCOL_ERROR = 1002

# Indicates that an endpoint is terminating the connection because it has received a type of data it cannot accept.
INVALID_DATA = 1003

# There are other status codes but most of them are "implementation specific".
end

class ProtocolError < HTTP::ProtocolError
# Raised by stream or connection handlers, results in GOAWAY frame
# which signals termination of the current connection. You *cannot*
# recover from this exception, or any exceptions subclassed from it.
class ProtocolError < Error
def initialize(message, code = PROTOCOL_ERROR)
super(message)

@code = code
end

attr :code
end

# When the frame payload does not match expectations.
class FrameSizeError < ProtocolError
end
end
end
3 changes: 2 additions & 1 deletion protocol-websocket.gemspec
Expand Up @@ -18,7 +18,8 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

spec.add_dependency "protocol-http"
spec.add_dependency "protocol-http", "~> 0.2"
spec.add_dependency "protocol-http1", "~> 0.2"

spec.add_development_dependency "covered"
spec.add_development_dependency "bundler"
Expand Down

0 comments on commit b46f571

Please sign in to comment.