Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-26 02:50:28 +01:00
Additional error handling
Dieser Commit ist enthalten in:
Ursprung
95ba52f973
Commit
4f195c704a
1 geänderte Dateien mit 4 neuen und 3 gelöschten Zeilen
|
@ -400,7 +400,7 @@ class CustomWizard::Builder
|
||||||
if action['api_body'] != ""
|
if action['api_body'] != ""
|
||||||
begin
|
begin
|
||||||
api_body_parsed = JSON.parse(action['api_body'])
|
api_body_parsed = JSON.parse(action['api_body'])
|
||||||
rescue
|
rescue JSON::ParserError
|
||||||
raise Discourse::InvalidParameters, "Invalid API body definition: #{action['api_body']} for #{action['title']}"
|
raise Discourse::InvalidParameters, "Invalid API body definition: #{action['api_body']} for #{action['title']}"
|
||||||
end
|
end
|
||||||
api_body = CustomWizard::Builder.fill_placeholders(JSON.generate(api_body_parsed), user, data)
|
api_body = CustomWizard::Builder.fill_placeholders(JSON.generate(api_body_parsed), user, data)
|
||||||
|
@ -408,8 +408,9 @@ class CustomWizard::Builder
|
||||||
|
|
||||||
result = CustomWizard::Api::Endpoint.request(action['api'], action['api_endpoint'], api_body)
|
result = CustomWizard::Api::Endpoint.request(action['api'], action['api_endpoint'], api_body)
|
||||||
|
|
||||||
if result[0].has_key? 'error'
|
if error = result['error'] || (result[0] && result[0]['error'])
|
||||||
updater.errors.add(:send_message, result[0]['error'])
|
error = error['message'] || error
|
||||||
|
updater.errors.add(:send_to_api, error)
|
||||||
else
|
else
|
||||||
## add validation callback
|
## add validation callback
|
||||||
end
|
end
|
||||||
|
|
Laden …
In neuem Issue referenzieren