Exception: Baidupush::BaseError

Inherits:
RuntimeError
  • Object
show all
Defined in:
lib/Baidupush/base_error.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(error_type, error_msg = "") ⇒ BaseError

初始化Arguments:

error_type: (Integer)
error_msg:  (String)


29
30
31
32
33
# File 'lib/Baidupush/base_error.rb', line 29

def initialize(error_type,error_msg="")
  @type = error_type
  @msg = error_msg
  set_status
end

Instance Attribute Details

#msgObject (readonly)

错误的信息



11
12
13
# File 'lib/Baidupush/base_error.rb', line 11

def msg
  @msg
end

#statusObject (readonly)

获取状态值



9
10
11
# File 'lib/Baidupush/base_error.rb', line 9

def status
  @status
end

#typeObject (readonly)

To change this template use File | Settings | File Templates. 错误的类型



7
8
9
# File 'lib/Baidupush/base_error.rb', line 7

def type
  @type
end

Class Method Details

.missing_parametersObject

缺少某些参数



15
16
17
# File 'lib/Baidupush/base_error.rb', line 15

def self.missing_parameters
  1
end

Instance Method Details

#default_error_msgObject



40
41
42
43
44
45
46
47
48
49
# File 'lib/Baidupush/base_error.rb', line 40

def default_error_msg
  case @type
    when 0
      "未知错误"
    when 1
      "缺少某些参数"
    else
      "未知错误"
  end
end

#error_num_startObject

子类应该重写此方法为每个子类分配不同的错误起始状态值



21
22
23
# File 'lib/Baidupush/base_error.rb', line 21

def error_num_start
  100
end

#get_error_msgObject

用于子类中定义独属于子类的错误Example:

>> BaseError.new.get_error_msg
=> {:simale=>"缺少某些参数",:detailed=>"缺少参数name"}


55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/Baidupush/base_error.rb', line 55

def get_error_msg
  ret = default_error_msg
  if ret.eql?("未知错误")
    case @type
      when 0
        ret = "未知错误"
      when 1
        ret = "缺少某些参数"
      else
        ret = "未知错误"
    end
  end
  ret = {:simaple => ret, :detailed => @msg}
end

#set_statusObject



70
71
72
# File 'lib/Baidupush/base_error.rb', line 70

def set_status
  @status = error_num_start + @type
end