Added prefilters to help locate 422 on issue creation.

This is an effort to figure out why I get 422 Unprocessable Entity errors sometimes when creating new issues.
This commit is contained in:
2026-02-08 09:58:34 -05:00
parent d063494bd2
commit 0e3318efdd
2 changed files with 29 additions and 2 deletions

View File

@@ -99,4 +99,6 @@ en:
notice_invoice_not_found: "Invoice not found"
notice_forbidden: "You do not have permission to access this resource"
notice_issue_not_found: "Issue not found"
customer_details: "Customer Details"
customer_details: "Customer Details"
notice_error_project_nil: "The issue's project is nil."
notice_error_project_nil: "The issue's tracker is nil."

View File

@@ -22,11 +22,36 @@ module RedmineQbo
end
def self.included(base)
base.class_eval do
helper Helper
before_action :error_check, only: [:create]
before_action :reload_new_issue, only: [:new]
end
end
# Check for errors when creating an issue.
# If the project or tracker is not set, reload the new issue form with an error message.
def error_check
logger.info "Creating issue for: #{@issue.project}"
update_issue_from_params
if @issue.project.nil?
flash[:error] = t :notice_error_project_nil
render :new, status: :unprocessable_entity
end
if @issue.project.nil?
flash[:error] = t :notice_error_tracker_nil
render :new, status: :unprocessable_entity
end
end
# Reload the new issue form with a default tracker and project if not set.
# This is needed to prevent errors when creating an issue without selecting a project or tracker.
def reload_new_issue
logger.info "Reloading new #{@issue.tracker} issue for: #{@project}"
@issue.tracker ||= Tracker.first
@project ||= Project.first
logger.info "Reloaded new #{@issue.tracker} issue for: #{@project}"
end
end