Class: Tng::Services::RepairService
- Inherits:
-
Object
- Object
- Tng::Services::RepairService
- Defined in:
- lib/tng/services/repair_service.rb
Constant Summary collapse
- REPAIR_PATH =
"cli/tng_rails/contents/repair"
Instance Method Summary collapse
-
#initialize(http_client) ⇒ RepairService
constructor
A new instance of RepairService.
- #repair_file(file_path, error_type, error_message, context_info = {}) ⇒ Object
Constructor Details
#initialize(http_client) ⇒ RepairService
Returns a new instance of RepairService.
11 12 13 |
# File 'lib/tng/services/repair_service.rb', line 11 def initialize(http_client) @http_client = http_client end |
Instance Method Details
#repair_file(file_path, error_type, error_message, context_info = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/tng/services/repair_service.rb', line 15 def repair_file(file_path, error_type, , context_info = {}) file_content = File.read(file_path) payload = { file_path: file_path, file_content: file_content, error_type: error_type, error_message: , context_info: context_info } # Compress payload json_payload = payload.to_json compressed_payload = Zlib::Deflate.deflate(json_payload) response = @http_client.post_binary(REPAIR_PATH, compressed_payload) return { error: :network_error, message: "Network error" } if response.is_a?(HTTPX::ErrorResponse) return { error: :auth_failed, message: "Auth failed" } if [401, 403].include?(response.status) begin data = JSON.parse(response.body) if data["error"] { error: :server_error, message: data["error"] } else data["result"] # This contains { file_content, explanation, applied_fixes } end rescue JSON::ParserError => e { error: :parse_error, message: "Failed to parse repair response: #{e.message}" } end end |