mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2026-02-13 01:03:59 -05:00
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:
@@ -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."
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user