fix: PDF errors not loading in CI (#13236)
This commit is contained in:
@@ -19,7 +19,7 @@ class Captain::Llm::PaginatedFaqGeneratorService < Llm::LegacyBaseOpenAiService
|
|||||||
end
|
end
|
||||||
|
|
||||||
def generate
|
def generate
|
||||||
raise CustomExceptions::PdfFaqGenerationError, I18n.t('captain.documents.missing_openai_file_id') if @document&.openai_file_id.blank?
|
raise CustomExceptions::Pdf::FaqGenerationError, I18n.t('captain.documents.missing_openai_file_id') if @document&.openai_file_id.blank?
|
||||||
|
|
||||||
generate_paginated_faqs
|
generate_paginated_faqs
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ class Captain::Llm::PdfProcessingService < Llm::LegacyBaseOpenAiService
|
|||||||
return if document.openai_file_id.present?
|
return if document.openai_file_id.present?
|
||||||
|
|
||||||
file_id = upload_pdf_to_openai
|
file_id = upload_pdf_to_openai
|
||||||
raise CustomExceptions::PdfUploadError, I18n.t('captain.documents.pdf_upload_failed') if file_id.blank?
|
raise CustomExceptions::Pdf::UploadError, I18n.t('captain.documents.pdf_upload_failed') if file_id.blank?
|
||||||
|
|
||||||
document.store_openai_file_id(file_id)
|
document.store_openai_file_id(file_id)
|
||||||
end
|
end
|
||||||
|
|||||||
19
lib/custom_exceptions/pdf.rb
Normal file
19
lib/custom_exceptions/pdf.rb
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
module CustomExceptions::Pdf
|
||||||
|
class UploadError < CustomExceptions::Base
|
||||||
|
def initialize(message = 'PDF upload failed')
|
||||||
|
super(message)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class ValidationError < CustomExceptions::Base
|
||||||
|
def initialize(message = 'PDF validation failed')
|
||||||
|
super(message)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class FaqGenerationError < CustomExceptions::Base
|
||||||
|
def initialize(message = 'PDF FAQ generation failed')
|
||||||
|
super(message)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
module CustomExceptions
|
|
||||||
class PdfProcessingError < Base
|
|
||||||
def initialize(message = 'PDF processing failed')
|
|
||||||
super(message)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
class PdfUploadError < PdfProcessingError
|
|
||||||
def initialize(message = 'PDF upload failed')
|
|
||||||
super(message)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
class PdfValidationError < PdfProcessingError
|
|
||||||
def initialize(message = 'PDF validation failed')
|
|
||||||
super(message)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
class PdfFaqGenerationError < PdfProcessingError
|
|
||||||
def initialize(message = 'PDF FAQ generation failed')
|
|
||||||
super(message)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
require 'custom_exceptions/pdf_processing_error'
|
|
||||||
|
|
||||||
RSpec.describe Captain::Llm::PaginatedFaqGeneratorService do
|
RSpec.describe Captain::Llm::PaginatedFaqGeneratorService do
|
||||||
let(:document) { create(:captain_document) }
|
let(:document) { create(:captain_document) }
|
||||||
@@ -23,7 +22,7 @@ RSpec.describe Captain::Llm::PaginatedFaqGeneratorService do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it 'raises an error' do
|
it 'raises an error' do
|
||||||
expect { service.generate }.to raise_error(CustomExceptions::PdfFaqGenerationError)
|
expect { service.generate }.to raise_error(CustomExceptions::Pdf::FaqGenerationError)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
require 'custom_exceptions/pdf_processing_error'
|
|
||||||
|
|
||||||
RSpec.describe Captain::Llm::PdfProcessingService do
|
RSpec.describe Captain::Llm::PdfProcessingService do
|
||||||
let(:document) { create(:captain_document) }
|
let(:document) { create(:captain_document) }
|
||||||
@@ -52,7 +51,7 @@ RSpec.describe Captain::Llm::PdfProcessingService do
|
|||||||
it 'raises error when upload fails' do
|
it 'raises error when upload fails' do
|
||||||
allow(mock_client.files).to receive(:upload).and_return({ 'id' => nil })
|
allow(mock_client.files).to receive(:upload).and_return({ 'id' => nil })
|
||||||
|
|
||||||
expect { service.process }.to raise_error(CustomExceptions::PdfUploadError)
|
expect { service.process }.to raise_error(CustomExceptions::Pdf::UploadError)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user