mirror of
https://github.com/vidarh/ruby-x11
synced 2024-12-26 09:59:02 +01:00
inherit custom errors from StandardError
This commit is contained in:
parent
910924a36d
commit
5663788eb8
2 changed files with 11 additions and 19 deletions
|
@ -1,3 +1,7 @@
|
|||
module X11
|
||||
class X11Error < StandardError; end
|
||||
end
|
||||
|
||||
require 'socket'
|
||||
require 'active_support'
|
||||
require 'hexdump'
|
||||
|
@ -6,8 +10,3 @@ require 'X11/auth'
|
|||
require 'X11/display'
|
||||
require 'X11/encode'
|
||||
require 'X11/packet'
|
||||
|
||||
module X11
|
||||
class X11Error < StandardError; end
|
||||
class X11Exception < RuntimeException; end
|
||||
end
|
||||
|
|
|
@ -1,15 +1,8 @@
|
|||
module X11
|
||||
|
||||
class DisplayException < X11Exception; end
|
||||
class ConnectionException < DisplayException; end
|
||||
|
||||
class AuthorizationException < ConnectionException
|
||||
attr_reader :errorcode
|
||||
def initialize msg, errcode=nil
|
||||
super msg
|
||||
@errorcode = errcode
|
||||
end
|
||||
end
|
||||
class DisplayError < X11Error; end
|
||||
class ConnectionError < DisplayError; end
|
||||
class AuthorizationError < ConnectionError; end
|
||||
|
||||
class Display
|
||||
|
||||
|
@ -53,14 +46,14 @@ private
|
|||
when X11::Auth::FAILED
|
||||
len, major, minor, xlen = @socket.read(7).unpack("CSSS")
|
||||
reason = @socket.read(xlen * 4)
|
||||
reason = reason[0..len]
|
||||
raise AuthorizationException.new "Connection to server failed -- (version #{major}.#{minor}) #{reason}", X11::Auth::FAILED
|
||||
reason = reason[0..len]
|
||||
raise AuthorizationError, "Connection to server failed -- (version #{major}.#{minor}) #{reason}"
|
||||
when X11::Auth::AUTHENTICATE
|
||||
raise AuthorizationException.new "Connection requires authentication", X11::Auth::AUTHENTICATE
|
||||
raise AuthorizationError, "Connection requires authentication"
|
||||
when X11::Auth::SUCCESS
|
||||
puts "CONNECTION SUCCESS"
|
||||
else
|
||||
raise AuthorizationException.new "Received unknown opcode #{type}"
|
||||
raise AuthorizationError, "Received unknown opcode #{type}"
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue