Exception: Trac::TracException

Inherits:
Exception
  • Object
show all
Defined in:
lib/trac4r/error.rb

Instance Method Summary collapse

Constructor Details

#initialize(http_error, host, port, path, method, args) ⇒ TracException

Creates new TracException

http_error

the error message, possibly mulit-line

host

host on which we are connecting to Trac

port

port we’re using

path

the path to the Trac API

method

the XML RPC method being called

args

the args (as an array) that were sent with the call



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/trac4r/error.rb', line 11

def initialize(http_error,host,port,path,method,args)
  http_error = http_error.sub 'HTTP-Error: ',''
  if http_error =~ /\n/
    http_error.split(/\n/).each do |line|
      if line =~ /^\d\d\d/
        http_error = line
        break
      end
    end
  end
  @http_status,@http_message = http_error.split(/\s+/,2)
  @host = host
  @port = port
  @path = path
  @method = method
  @args = args
end

Instance Method Details

#messageObject

Gives a more useful message for common problems



30
31
32
33
34
35
36
37
38
# File 'lib/trac4r/error.rb', line 30

def message
  if @http_status == '404'
    "Couldn't find Trac API at #{url}, check your configuration"
  elsif @http_status == '401'
    "Your username/password didn't authenticate, check your configuration"
  else
    "#{@http_message} (#{@http_status}) when trying URL http://#{@host}:#{@port}#{@path} and method #{@command}(#{@args.join('.')})"
  end
end

#urlObject



40
41
42
# File 'lib/trac4r/error.rb', line 40

def url
  "http://#{@host}:#{@port}#{@path}"
end