Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
leopard (0.1.5)
leopard (0.1.6)
concurrent-ruby (~> 1.1)
dry-configurable (~> 1.3)
dry-monads (~> 1.9)
Expand Down
3 changes: 2 additions & 1 deletion examples/echo_endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def initialize(a_var = 1)
end

endpoint(:echo) { |msg| Success(msg.data) }
endpoint(:echo_fail) { |msg| Failure({ failure: '*boom*', data: msg.data }.to_json) }
end

if __FILE__ == $PROGRAM_NAME
Expand All @@ -22,6 +23,6 @@ def initialize(a_var = 1)
version: '1.0.0',
instance_args: [2],
},
instances: 4,
instances: 1,
)
end
5 changes: 2 additions & 3 deletions lib/leopard/message_wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@ def respond(payload)
end

# @param err [String, Exception] The error message or exception to respond with.
# @param code [Integer] The HTTP status code to use for the error response.
#
# @return [void]
def respond_with_error(err, code: 500)
raw.respond_with_error(err.to_s, code:)
def respond_with_error(err)
raw.respond_with_error(err.to_s)
end

private
Expand Down
10 changes: 5 additions & 5 deletions test/lib/message_wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ def respond(payload)
@responded_payload = payload
end

def respond_with_error(err, code:)
@error_args = [err, code]
def respond_with_error(err)
@error_args = [err]
end
end

Expand Down Expand Up @@ -57,15 +57,15 @@ def respond_with_error(err, code:)
end

it 'responds with error' do
wrapper.respond_with_error('fail', code: 404)
wrapper.respond_with_error('fail')

assert_equal ['fail', 404], msg.error_args
assert_equal ['fail'], msg.error_args
end

it 'coerces exception objects to strings when responding with error' do
err = StandardError.new('broken')
wrapper.respond_with_error(err)

assert_equal ['broken', 500], msg.error_args
assert_equal ['broken'], msg.error_args
end
end