Skip to content

Commit b5ad0ca

Browse files
markokajzerdblock
andauthored
grape v3 compatibility (#180)
* replace deprecated rack_response with error! * rubocop * changelog * Update CHANGELOG.md Co-authored-by: Daniel (dB.) Doubrovkine <[email protected]> --------- Co-authored-by: Daniel (dB.) Doubrovkine <[email protected]>
1 parent f8f343b commit b5ad0ca

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
### 2.2.1 (Next)
44

55
* Your contribution here.
6+
* [#180](https://github.com/slack-ruby/slack-ruby-bot-server/pull/180): Add support for Grape v3 - [@markokajzer](https://github.com/markokajzer).
67

78
### 2.2.0 (2025/09/22)
89

lib/slack-ruby-bot-server/api/helpers/error_helpers.rb

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,42 +10,42 @@ module ErrorHelpers
1010
Middleware.logger.error "#{e.class.name}: #{e.message}\n #{backtrace}"
1111
error = { type: 'other_error', message: e.message }
1212
error[:backtrace] = backtrace
13-
rack_response(error.to_json, 400)
13+
error!(error, 400)
1414
end
1515
# rescue document validation errors into detail json
1616
if SlackRubyBotServer::Config.mongoid?
1717
rescue_from Mongoid::Errors::Validations do |e|
1818
backtrace = e.backtrace[0..5].join("\n ")
1919
Middleware.logger.warn "#{e.class.name}: #{e.message}\n #{backtrace}"
20-
rack_response({
21-
type: 'param_error',
22-
message: e.document.errors.full_messages.uniq.join(', ') + '.',
23-
detail: e.document.errors.messages.each_with_object({}) do |(k, v), h|
24-
h[k] = v.uniq
25-
end
26-
}.to_json, 400)
20+
error!({
21+
type: 'param_error',
22+
message: e.document.errors.full_messages.uniq.join(', ') + '.',
23+
detail: e.document.errors.messages.each_with_object({}) do |(k, v), h|
24+
h[k] = v.uniq
25+
end
26+
}, 400)
2727
end
2828
end
2929
rescue_from Grape::Exceptions::Validation do |e|
3030
backtrace = e.backtrace[0..5].join("\n ")
3131
Middleware.logger.warn "#{e.class.name}: #{e.message}\n #{backtrace}"
32-
rack_response({
33-
type: 'param_error',
34-
message: 'Invalid parameters.',
35-
detail: { e.params.join(', ') => [e.message] }
36-
}.to_json, 400)
32+
error!({
33+
type: 'param_error',
34+
message: 'Invalid parameters.',
35+
detail: { e.params.join(', ') => [e.message] }
36+
}, 400)
3737
end
3838
rescue_from Grape::Exceptions::ValidationErrors do |e|
3939
backtrace = e.backtrace[0..5].join("\n ")
4040
Middleware.logger.warn "#{e.class.name}: #{e.message}\n #{backtrace}"
41-
rack_response({
42-
type: 'param_error',
43-
message: 'Invalid parameters.',
44-
detail: e.errors.each_with_object({}) do |(k, v), h|
45-
# JSON does not permit having a key of type Array
46-
h[k.count == 1 ? k.first : k.join(', ')] = v
47-
end
48-
}.to_json, 400)
41+
error!({
42+
type: 'param_error',
43+
message: 'Invalid parameters.',
44+
detail: e.errors.each_with_object({}) do |(k, v), h|
45+
# JSON does not permit having a key of type Array
46+
h[k.count == 1 ? k.first : k.join(', ')] = v
47+
end
48+
}, 400)
4949
end
5050
end
5151
end

0 commit comments

Comments
 (0)