-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors.rb
68 lines (56 loc) · 1.76 KB
/
errors.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# frozen_string_literal: true
module Seam
module Errors
# HTTP
class SeamHttpApiError < StandardError
attr_reader :code, :status_code, :request_id, :data
def initialize(error, status_code, request_id)
super(error[:message])
@code = error[:type]
@status_code = status_code
@request_id = request_id
@data = error[:data]
end
end
class SeamHttpUnauthorizedError < SeamHttpApiError
def initialize(request_id)
super({type: "unauthorized", message: "Unauthorized"}, 401, request_id)
end
end
class SeamHttpInvalidInputError < SeamHttpApiError
attr_reader :validation_errors
def initialize(error, status_code, request_id)
super(error, status_code, request_id)
@code = "invalid_input"
@validation_errors = error["validation_errors"] || {}
end
def get_validation_error_messages(param_name)
@validation_errors.dig(param_name, "_errors") || []
end
end
# Action attempt
class SeamActionAttemptError < StandardError
attr_reader :action_attempt
def initialize(message, action_attempt)
super(message)
@action_attempt = action_attempt
end
def name
self.class.name
end
end
class SeamActionAttemptFailedError < SeamActionAttemptError
attr_reader :code
def initialize(action_attempt)
super(action_attempt.error.message, action_attempt)
@code = action_attempt.error.type
end
end
class SeamActionAttemptTimeoutError < SeamActionAttemptError
def initialize(action_attempt, timeout)
message = "Timed out waiting for action attempt after #{timeout}s"
super(message, action_attempt)
end
end
end
end