[29942] Better error messages for permission failures

[ci skip]

https://community.openproject.com/wp/29942
pull/7357/head
Oliver Günther 6 years ago
parent b2d3cb983c
commit c775dc8031
  1. 1
      config/locales/en.yml
  2. 0
      files/delete.me
  3. 2
      lib/api/errors/internal_error.rb
  4. 8
      lib/api/v3/attachments/attachments_by_container_api.rb

@ -2659,6 +2659,7 @@ en:
multipart_body_error: "The request body did not contain the expected multipart parts." multipart_body_error: "The request body did not contain the expected multipart parts."
multiple_errors: "Multiple field constraints have been violated." multiple_errors: "Multiple field constraints have been violated."
unable_to_create_attachment: "The attachment could not be created" unable_to_create_attachment: "The attachment could not be created"
unable_to_create_attachment_permissions: "The attachment could not be saved due to lacking file system permissions"
render: render:
context_not_parsable: "The context provided is not a link to a resource." context_not_parsable: "The context provided is not a link to a resource."
unsupported_context: "The resource given is not supported as context." unsupported_context: "The resource given is not supported as context."

@ -36,7 +36,7 @@ module API
def initialize(error_message = nil) def initialize(error_message = nil)
error = I18n.t('api_v3.errors.code_500') error = I18n.t('api_v3.errors.code_500')
if message if error_message
error += " #{error_message}" error += " #{error_message}"
end end

@ -93,7 +93,13 @@ module API
raise ::API::Errors::ErrorBase.create_and_merge_errors(error.record.errors) raise ::API::Errors::ErrorBase.create_and_merge_errors(error.record.errors)
rescue StandardError => error rescue StandardError => error
log_attachment_saving_error(error) log_attachment_saving_error(error)
raise ::API::Errors::InternalError.new(I18n.t('api_v3.errors.unable_to_create_attachment')) message =
if error&.class&.to_s == 'Errno::EACCES'
I18n.t('api_v3.errors.unable_to_create_attachment_permissions')
else
I18n.t('api_v3.errors.unable_to_create_attachment')
end
raise ::API::Errors::InternalError.new(message)
end end
def log_attachment_saving_error(error) def log_attachment_saving_error(error)

Loading…
Cancel
Save