diff --git a/app/controllers/api/v1/accounts/integrations/linear_controller.rb b/app/controllers/api/v1/accounts/integrations/linear_controller.rb index 46169ddf5..c5482b22f 100644 --- a/app/controllers/api/v1/accounts/integrations/linear_controller.rb +++ b/app/controllers/api/v1/accounts/integrations/linear_controller.rb @@ -1,6 +1,4 @@ class Api::V1::Accounts::Integrations::LinearController < Api::V1::Accounts::BaseController - # before_action :fetch_conversation, only: [:list] - def teams teams = linear_processor_service.teams if teams.is_a?(Hash) && teams[:error] @@ -23,14 +21,10 @@ class Api::V1::Accounts::Integrations::LinearController < Api::V1::Accounts::Bas private def linear_processor_service - Integrations::Linear::ProcessorService.new(account: Current.account, conversation: @conversation) + Integrations::Linear::ProcessorService.new(account: Current.account) end def permitted_params params.permit(:conversation_id) end - - def fetch_conversation - @conversation = Current.account.conversations.find_by!(display_id: permitted_params[:conversation_id]) - end end diff --git a/lib/integrations/linear/processor_service.rb b/lib/integrations/linear/processor_service.rb index 9cae7198d..0187b6b6a 100644 --- a/lib/integrations/linear/processor_service.rb +++ b/lib/integrations/linear/processor_service.rb @@ -1,5 +1,5 @@ class Integrations::Linear::ProcessorService - pattr_initialize [:account!, :conversation!] + pattr_initialize [:account!] def teams response = linear_client.teams @@ -22,10 +22,6 @@ class Integrations::Linear::ProcessorService private - def conversation_link - "#{ENV.fetch('FRONTEND_URL', nil)}/app/accounts/#{account.id}/conversations/#{conversation.display_id}" - end - def linear_hook @linear_hook ||= account.hooks.find_by!(app_id: 'linear') end diff --git a/lib/linear.rb b/lib/linear.rb index e49c4e3ff..1169b3c9e 100644 --- a/lib/linear.rb +++ b/lib/linear.rb @@ -31,17 +31,18 @@ class Linear def execute_query(query) response = @client.query(query) - unless response.data - raise StandardError, "Error retrieving data: #{response.errors.messages}" if response.errors.any? - - return { error: 'No data returned' } - end + log_and_return_error("Error retrieving data: #{response.errors.messages}") if response.data.nil? && response.errors.any? response.data.to_h rescue Graphlient::Errors::GraphQLError => e - { error: "GraphQL Error: #{e.message}" } + log_and_return_error("GraphQL Error: #{e.message}") rescue Graphlient::Errors::ServerError => e - { error: "Server Error: #{e.message}" } + log_and_return_error("Server Error: #{e.message}") rescue StandardError => e - { error: "Unexpected Error: #{e.message}" } + log_and_return_error("Unexpected Error: #{e.message}") + end + + def log_and_return_error(message) + Rails.logger.error message + { error: message } end end diff --git a/spec/lib/integrations/linear/processor_service_spec.rb b/spec/lib/integrations/linear/processor_service_spec.rb index 0249e7806..122e84072 100644 --- a/spec/lib/integrations/linear/processor_service_spec.rb +++ b/spec/lib/integrations/linear/processor_service_spec.rb @@ -2,8 +2,7 @@ require 'rails_helper' describe Integrations::Linear::ProcessorService do let(:account) { create(:account) } - let(:conversation) { create(:conversation, account: account) } - let(:processor) { described_class.new(account: account, conversation: conversation) } + let(:processor) { described_class.new(account: account) } let(:api_key) { 'valid_api_key' } let(:url) { 'https://api.linear.app/graphql' } let(:headers) { { 'Content-Type' => 'application/json', 'Authorization' => api_key } }