From 59a79f715b482433cf49f64ab6174c5479a965b5 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 13 Jan 2020 17:23:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A0=E6=95=88=E7=9A=84utf-8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/concerns/git_helper.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/controllers/concerns/git_helper.rb b/app/controllers/concerns/git_helper.rb index ec0f2ad82..abedd4dda 100644 --- a/app/controllers/concerns/git_helper.rb +++ b/app/controllers/concerns/git_helper.rb @@ -13,7 +13,7 @@ module GitHelper content = GitService.file_content(repo_path: repo_path, path: path) - Rails.logger.info("git file content: content is #{content}") + #Rails.logger.info("git file content: content is #{content}") decode_content = nil if content.present? content = content["content"] #6.24 -hs 这个为新增,因为当实训题里含有选择题时,这里会报错,undefined method `[]' for nil:NilClass @@ -26,7 +26,7 @@ module GitHelper if cd["encoding"] == 'GB18030' && cd['confidence'] > 0.8 content.encode('UTF-8', 'GBK', {:invalid => :replace, :undef => :replace, :replace => ' '}) elsif cd['encoding'].blank? - raise("无效的utf-8文件") + raise("ERROR_UTF8") else Rails.logger.info("####encoding:#{content.encoding}") content.force_encoding('UTF-8') @@ -37,7 +37,8 @@ module GitHelper rescue Exception => e Rails.logger.error(e.message) - raise Educoder::TipException.new("文档内容获取异常") + error_msg = e.message == "ERROR_UTF8" ? "文件无法预览" : "文档内容获取异常" + raise Educoder::TipException.new(error_msg) end end