[#40228] added error handling for creating file links

pull/10183/head
Eric Schubert 3 years ago
parent 9138b2d134
commit 970f00ae05
No known key found for this signature in database
GPG Key ID: 1D346C019BD4BAA2
  1. 1
      config/locales/en.yml
  2. 17
      lib/api/utilities/endpoints/modify.rb
  3. 6
      modules/storages/lib/api/v3/file_links/create_endpoint.rb
  4. 4
      modules/storages/spec/requests/api/v3/file_links/file_links_spec.rb

@ -1276,6 +1276,7 @@ en:
error_enterprise_token_invalid_domain: "The Enterprise Edition is not active. Your Enterprise token's domain (%{actual}) does not match the system's host name (%{expected})."
error_failed_to_delete_entry: 'Failed to delete this entry.'
error_in_dependent: "Error attempting to alter dependent object: %{dependent_class} #%{related_id} - %{related_subject}: %{error}"
error_in_new_dependent: "Error attempting to create dependent object: %{dependent_class} - %{related_subject}: %{error}"
error_invalid_selected_value: "Invalid selected value."
error_journal_attribute_not_present: "Journal does not contain attribute %{attribute}."
error_pdf_export_too_many_columns: "Too many columns selected for the PDF export. Please reduce the number of columns."

@ -36,6 +36,12 @@ module API
end
end
protected
def build_error_from_result(result)
ActiveModel::Errors.new result
end
private
def present_success(_request, _call)
@ -56,7 +62,7 @@ module API
end
def merge_dependent_errors(call)
errors = ActiveModel::Errors.new call.result
errors = build_error_from_result(call.result)
call.dependent_results.each do |dr|
dr.errors.full_messages.each do |full_message|
@ -68,8 +74,15 @@ module API
end
def dependent_error_message(result, full_message)
key =
if result.id.blank?
:error_in_new_dependent
else
:error_in_dependent
end
I18n.t(
:error_in_dependent,
key,
dependent_class: result.model_name.human,
related_id: result.id,
# TODO: Make it more robust, as not every model has a 'name' attribute (e.g. fall back to collection index?)

@ -24,6 +24,12 @@ module API::V3::FileLinks
)
end
protected
def build_error_from_result(result)
ActiveModel::Errors.new result.first
end
private
def params_modifier

@ -174,7 +174,9 @@ describe 'API v3 file links resource', type: :request do
}
end
it_behaves_like 'invalid request body'
it_behaves_like 'constraint violation' do
let(:message) { 'Storage is invalid' }
end
end
end

Loading…
Cancel
Save