Skip to content

Commit 13c56b1

Browse files
committed
DRY missing endpoint exception
1 parent 65b2901 commit 13c56b1

File tree

7 files changed

+22
-79
lines changed

7 files changed

+22
-79
lines changed

lib/datadog/core/remote/transport/http/config.rb

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -177,25 +177,10 @@ def config=(endpoint)
177177
end
178178

179179
def send_config(env, &block)
180-
raise NoConfigEndpointDefinedError, self if config.nil?
180+
raise Core::Transport::HTTP::API::Spec::EndpointNotDefinedError.new(self, 'config') if config.nil?
181181

182182
config.call(env, &block)
183183
end
184-
185-
# Raised when traces sent but no traces endpoint is defined
186-
class NoConfigEndpointDefinedError < StandardError
187-
attr_reader :spec
188-
189-
def initialize(spec)
190-
super()
191-
192-
@spec = spec
193-
end
194-
195-
def message
196-
'No config endpoint is defined for API specification!'
197-
end
198-
end
199184
end
200185

201186
# Extensions for HTTP API Instance

lib/datadog/core/remote/transport/http/negotiation.rb

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,25 +50,10 @@ def info=(endpoint)
5050
end
5151

5252
def send_info(env, &block)
53-
raise NoNegotiationEndpointDefinedError, self if info.nil?
53+
raise Core::Transport::HTTP::API::Spec::EndpointNotDefinedError.new(self, 'info') if info.nil?
5454

5555
info.call(env, &block)
5656
end
57-
58-
# Raised when traces sent but no traces endpoint is defined
59-
class NoNegotiationEndpointDefinedError < StandardError
60-
attr_reader :spec
61-
62-
def initialize(spec)
63-
super()
64-
65-
@spec = spec
66-
end
67-
68-
def message
69-
'No info endpoint is defined for API specification!'
70-
end
71-
end
7257
end
7358

7459
# Extensions for HTTP API Instance

lib/datadog/core/transport/http/api/spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,22 @@ module API
88
# Specification for an HTTP API
99
# Defines behaviors without specific configuration details.
1010
class Spec
11+
class EndpointNotDefinedError < StandardError
12+
attr_reader :spec
13+
attr_reader :endpoint_name
14+
15+
def initialize(spec, endpoint_name)
16+
@spec = spec
17+
@endpoint_name = endpoint_name
18+
19+
super(message)
20+
end
21+
22+
def message
23+
"No #{endpoint_name} endpoint is defined for API specification!"
24+
end
25+
end
26+
1127
def initialize
1228
yield(self) if block_given?
1329
end

lib/datadog/di/transport/http/diagnostics.rb

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,24 +44,10 @@ module Spec
4444
attr_accessor :diagnostics
4545

4646
def send_diagnostics(env, &block)
47-
raise NoDiagnosticsEndpointDefinedError, self if diagnostics.nil?
47+
raise Core::Transport::HTTP::API::Spec::EndpointNotDefinedError.new(self, 'diagnostics') if diagnostics.nil?
4848

4949
diagnostics.call(env, &block)
5050
end
51-
52-
class NoDiagnosticsEndpointDefinedError < StandardError
53-
attr_reader :spec
54-
55-
def initialize(spec)
56-
super
57-
58-
@spec = spec
59-
end
60-
61-
def message
62-
'No diagnostics endpoint is defined for API specification!'
63-
end
64-
end
6551
end
6652

6753
# Endpoint for negotiation

lib/datadog/di/transport/http/input.rb

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,24 +44,10 @@ module Spec
4444
attr_accessor :input
4545

4646
def send_input(env, &block)
47-
raise NoInputEndpointDefinedError, self if input.nil?
47+
raise Core::Transport::HTTP::API::Spec::EndpointNotDefinedError.new(self, 'input') if input.nil?
4848

4949
input.call(env, &block)
5050
end
51-
52-
class NoInputEndpointDefinedError < StandardError
53-
attr_reader :spec
54-
55-
def initialize(spec)
56-
super
57-
58-
@spec = spec
59-
end
60-
61-
def message
62-
'No input endpoint is defined for API specification!'
63-
end
64-
end
6551
end
6652

6753
# Endpoint for negotiation

lib/datadog/tracing/transport/http/traces.rb

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,29 +44,14 @@ def traces=(endpoint)
4444
end
4545

4646
def send_traces(env, &block)
47-
raise NoTraceEndpointDefinedError, self if traces.nil?
47+
raise Core::Transport::HTTP::API::Spec::EndpointNotDefinedError.new(self, 'traces') if traces.nil?
4848

4949
traces.call(env, &block)
5050
end
5151

5252
def encoder
5353
traces.encoder
5454
end
55-
56-
# Raised when traces sent but no traces endpoint is defined
57-
class NoTraceEndpointDefinedError < StandardError
58-
attr_reader :spec
59-
60-
def initialize(spec)
61-
super
62-
63-
@spec = spec
64-
end
65-
66-
def message
67-
'No trace endpoint is defined for API specification!'
68-
end
69-
end
7055
end
7156

7257
# Extensions for HTTP API Instance

spec/datadog/tracing/transport/http/traces_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
it {
7171
expect do
7272
send_traces
73-
end.to raise_error(Datadog::Tracing::Transport::HTTP::Traces::API::Spec::NoTraceEndpointDefinedError)
73+
end.to raise_error(Datadog::Core::Transport::HTTP::API::Spec::EndpointNotDefinedError)
7474
}
7575
end
7676

0 commit comments

Comments
 (0)