Exception: Baidupush::BaseError
- Inherits:
-
RuntimeError
- Object
- RuntimeError
- Baidupush::BaseError
- Defined in:
- lib/Baidupush/base_error.rb
Instance Attribute Summary collapse
-
#msg ⇒ Object
readonly
错误的信息.
-
#status ⇒ Object
readonly
获取状态值.
-
#type ⇒ Object
readonly
To change this template use File | Settings | File Templates.
Class Method Summary collapse
-
.missing_parameters ⇒ Object
缺少某些参数.
Instance Method Summary collapse
- #default_error_msg ⇒ Object
-
#error_num_start ⇒ Object
子类应该重写此方法 为每个子类分配不同的错误起始状态值.
-
#get_error_msg ⇒ Object
用于子类中定义独属于子类的错误 Example: >> BaseError.new.get_error_msg => :simale=>“缺少某些参数”,:detailed=>“缺少参数name”.
-
#initialize(error_type, error_msg = "") ⇒ BaseError
constructor
初始化 Arguments: error_type: (Integer) error_msg: (String).
- #set_status ⇒ Object
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
#msg ⇒ Object (readonly)
错误的信息
11 12 13 |
# File 'lib/Baidupush/base_error.rb', line 11 def msg @msg end |
#status ⇒ Object (readonly)
获取状态值
9 10 11 |
# File 'lib/Baidupush/base_error.rb', line 9 def status @status end |
#type ⇒ Object (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_parameters ⇒ Object
缺少某些参数
15 16 17 |
# File 'lib/Baidupush/base_error.rb', line 15 def self.missing_parameters 1 end |
Instance Method Details
#default_error_msg ⇒ Object
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_start ⇒ Object
子类应该重写此方法为每个子类分配不同的错误起始状态值
21 22 23 |
# File 'lib/Baidupush/base_error.rb', line 21 def error_num_start 100 end |
#get_error_msg ⇒ Object
用于子类中定义独属于子类的错误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_status ⇒ Object
70 71 72 |
# File 'lib/Baidupush/base_error.rb', line 70 def set_status @status = error_num_start + @type end |