From 90d03cf542e6930b5f2349a9f1aadb08f603011d Mon Sep 17 00:00:00 2001 From: Mantas Masalskis Date: Mon, 13 Dec 2021 07:59:20 +0100 Subject: [PATCH] Maintenance: CoreWorkflow throws more verbose exception --- app/models/concerns/checks_core_workflow.rb | 4 ++-- lib/exceptions.rb | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/models/concerns/checks_core_workflow.rb b/app/models/concerns/checks_core_workflow.rb index 83c149522..088027342 100644 --- a/app/models/concerns/checks_core_workflow.rb +++ b/app/models/concerns/checks_core_workflow.rb @@ -34,7 +34,7 @@ module ChecksCoreWorkflow next if self[key].blank? next if restricted_value?(perform_result, key) - raise Exceptions::UnprocessableEntity, "Invalid value '#{self[key]}' for field '#{key}'!" + raise Exceptions::ApplicationModel.new(self, "Invalid value '#{self[key]}' for field '#{key}'!") end end @@ -49,7 +49,7 @@ module ChecksCoreWorkflow next if !column_value?(key) next if !colum_default?(key) - raise Exceptions::UnprocessableEntity, "Missing required value for field '#{key}'!" + raise Exceptions::ApplicationModel.new(self, "Missing required value for field '#{key}'!") end end diff --git a/lib/exceptions.rb b/lib/exceptions.rb index 40068f820..41376bf25 100644 --- a/lib/exceptions.rb +++ b/lib/exceptions.rb @@ -8,6 +8,15 @@ module Exceptions class UnprocessableEntity < StandardError; end + class ApplicationModel < UnprocessableEntity + attr_reader :record + + def initialize(record, message) + super(message) + @record = record + end + end + def self.policy_class ExceptionsPolicy end