@@ -39,8 +39,8 @@ def self.create(config:, endpoints:, log:)
3939 content_type :xml , "application/xml"
4040 content_type :any , "*/*"
4141
42- format :txt # TODO: make this configurable via config[:format] (defaults to :json in the future)
43- default_format :txt # TODO: make this configurable via config[:default_format] (defaults to :json in the future)
42+ format config [ :format ] || :json
43+ default_format config [ :default_format ] || :json
4444 end
4545
4646 api_class . class_eval do
@@ -118,8 +118,7 @@ def self.create(config:, endpoints:, log:)
118118 log . info ( "successfully processed webhook event with handler: #{ handler_class_name } " )
119119 log . debug ( "processing duration: #{ Time . now - start_time } s" )
120120 status 200
121- content_type "application/json"
122- response . to_json
121+ response
123122 rescue Hooks ::Plugins ::Handlers ::Error => e
124123 # Handler called error! method - immediately return error response and exit the request
125124 log . debug ( "handler #{ handler_class_name } called `error!` method" )
@@ -132,8 +131,8 @@ def self.create(config:, endpoints:, log:)
132131 content_type "text/plain"
133132 error_response = e . body
134133 else
135- content_type "application/json"
136- error_response = e . body . to_json
134+ # Let Grape handle JSON conversion with the default format
135+ error_response = e . body
137136 end
138137
139138 return error_response
@@ -164,8 +163,7 @@ def self.create(config:, endpoints:, log:)
164163 error_response [ :handler ] = handler_class_name unless config [ :production ]
165164
166165 status determine_error_code ( e )
167- content_type "application/json"
168- error_response . to_json
166+ error_response
169167 end
170168 end
171169 end
0 commit comments