From c775dc80319051efc2f61d17d2c1766fcbc82312 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20G=C3=BCnther?= Date: Tue, 4 Jun 2019 07:43:04 +0200 Subject: [PATCH] [29942] Better error messages for permission failures [ci skip] https://community.openproject.com/wp/29942 --- config/locales/en.yml | 1 + files/delete.me | 0 lib/api/errors/internal_error.rb | 2 +- lib/api/v3/attachments/attachments_by_container_api.rb | 8 +++++++- 4 files changed, 9 insertions(+), 2 deletions(-) mode change 100644 => 100755 files/delete.me diff --git a/config/locales/en.yml b/config/locales/en.yml index f5c57a8b6b..f9cfde55b9 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2659,6 +2659,7 @@ en: multipart_body_error: "The request body did not contain the expected multipart parts." multiple_errors: "Multiple field constraints have been violated." 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: context_not_parsable: "The context provided is not a link to a resource." unsupported_context: "The resource given is not supported as context." diff --git a/files/delete.me b/files/delete.me old mode 100644 new mode 100755 diff --git a/lib/api/errors/internal_error.rb b/lib/api/errors/internal_error.rb index f418344a2b..701c92f7cd 100644 --- a/lib/api/errors/internal_error.rb +++ b/lib/api/errors/internal_error.rb @@ -36,7 +36,7 @@ module API def initialize(error_message = nil) error = I18n.t('api_v3.errors.code_500') - if message + if error_message error += " #{error_message}" end diff --git a/lib/api/v3/attachments/attachments_by_container_api.rb b/lib/api/v3/attachments/attachments_by_container_api.rb index 4b8f4d01d3..fb3e678961 100644 --- a/lib/api/v3/attachments/attachments_by_container_api.rb +++ b/lib/api/v3/attachments/attachments_by_container_api.rb @@ -93,7 +93,13 @@ module API raise ::API::Errors::ErrorBase.create_and_merge_errors(error.record.errors) rescue StandardError => 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 def log_attachment_saving_error(error)