Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

refactor: fluent error handling for service

Christophe Bliardb75c3a302237
diff --git a/modules/storages/app/controllers/storages/admin/projects_storages_controller.rb b/modules/storages/app/controllers/storages/admin/projects_storages_controller.rb
index 13256efaf6b..1047c2d9f18 100644
--- a/modules/storages/app/controllers/storages/admin/projects_storages_controller.rb
+++ b/modules/storages/app/controllers/storages/admin/projects_storages_controller.rb
@@ -103,14 +103,10 @@ class Storages::Admin::ProjectsStoragesController < Projects::SettingsController
def destroy
# The complex logic for deleting associated objects was moved into a service:
# https://dev.to/joker666/ruby-on-rails-pattern-service-objects-b19
- service_result = Storages::ProjectStorages::DeleteService
+ Storages::ProjectStorages::DeleteService
.new(user: current_user, model: @object)
.call
-
- # Handle errors.
- unless service_result.success?
- flash[:error] = service_result.errors.full_messages
- end
+ .on_failure { |service_result| flash[:error] = service_result.errors.full_messages }
# Redirect the user to the URL of Projects -> Settings -> File Storages
redirect_to project_settings_projects_storages_path