-
Notifications
You must be signed in to change notification settings - Fork 534
/
Copy patherror.rb
47 lines (42 loc) · 1.47 KB
/
error.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
module JSONAPI
class Error
attr_accessor :title, :detail, :id, :href, :code, :source, :links, :status, :meta
def initialize(options = {})
@title = options[:title]
@detail = options[:detail]
@id = options[:id]
@href = options[:href]
@code = if JSONAPI.configuration.use_text_errors
TEXT_ERRORS[options[:code]]
else
options[:code]
end
@source = options[:source]
@links = options[:links]
@status = Rack::Utils.status_code(options[:status]).to_s
@meta = options[:meta]
end
def to_hash
hash = {}
instance_variables.each {|var| hash[var.to_s.delete('@')] = instance_variable_get(var) unless instance_variable_get(var).nil? }
hash
end
end
class Warning
attr_accessor :title, :detail, :code
def initialize(options = {})
@title = options[:title]
@detail = options[:detail]
@code = if JSONAPI.configuration.use_text_errors
TEXT_ERRORS[options[:code]]
else
options[:code]
end
end
def to_hash
hash = {}
instance_variables.each {|var| hash[var.to_s.delete('@')] = instance_variable_get(var) unless instance_variable_get(var).nil? }
hash
end
end
end