Skip to content

Commit 7fdc19f

Browse files
committed
feat: serialize error payloads
1 parent 7b08dfa commit 7fdc19f

3 files changed

Lines changed: 4 additions & 3 deletions

File tree

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,4 @@ Gemfile.lock
5656
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
5757
.rubocop_cache
5858
# .rubocop-https?--*
59+
.idea

‎lib/leopard/message_wrapper.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def respond(payload)
3939
#
4040
# @return [void]
4141
def respond_with_error(err, &)
42-
raw.respond_with_error(err, &)
42+
raw.respond_with_error(err.is_a?(Exception) ? err : serialize(err), &)
4343
end
4444

4545
private

‎test/lib/message_wrapper.rb‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ def respond_with_error(err)
7575
assert_equal [err], msg.error_args
7676
end
7777

78-
it 'passes hash payloads through when responding with error' do
78+
it 'serializes hash payloads when responding with error' do
7979
err = { 'description' => 'broken', 'code' => 422 }
8080
wrapper.respond_with_error(err)
8181

82-
assert_equal [err], msg.error_args
82+
assert_equal ['{"description":"broken","code":422}'], msg.error_args
8383
end
8484

8585
it 'forwards blocks when responding with error' do

0 commit comments

Comments
 (0)