[Groonga-commit] ranguba/ranguba-server at d0a21e9 [master] Return response on error

Back to archive index

Kouhei Sutou null+****@clear*****
Wed Mar 1 23:54:52 JST 2017


Kouhei Sutou	2017-03-01 23:54:52 +0900 (Wed, 01 Mar 2017)

  New Revision: d0a21e931081026f45e025237fc12d81f34f96d9
  https://github.com/ranguba/ranguba-server/commit/d0a21e931081026f45e025237fc12d81f34f96d9

  Message:
    Return response on error

  Modified files:
    app/controllers/scrapings_controller.rb
    app/models/scraping.rb

  Modified: app/controllers/scrapings_controller.rb (+2 -1)
===================================================================
--- app/controllers/scrapings_controller.rb    2017-02-22 01:02:10 +0900 (45f829c)
+++ app/controllers/scrapings_controller.rb    2017-03-01 23:54:52 +0900 (43f49dd)
@@ -9,8 +9,9 @@ class ScrapingsController < ApplicationApiController
         format.html { redirect_to @entry, notice: 'Scraped successfully.' }
         format.json { render "entries/show", status: :created, location: @entry }
       else
+        @entry =****@scrap*****
         format.html { render :new }
-        format.json { render json: @scraping.errors, status: :unprocessable_entity }
+        format.json { render json: @entry.errors, status: :unprocessable_entity }
       end
     end
   end

  Modified: app/models/scraping.rb (+23 -9)
===================================================================
--- app/models/scraping.rb    2017-02-22 01:02:10 +0900 (bbdadce)
+++ app/models/scraping.rb    2017-03-01 23:54:52 +0900 (a3176cb)
@@ -16,18 +16,32 @@ class Scraping
     data.mime_type = mime_type
     data.body = body
     data.size = body.bytesize
-    texts = []
-    size = 0
-    extractor.extract(data) do |extracted_data|
-      text = extracted_data.body.encode(Encoding::UTF_8,
-                                        :invalid => :replace,
-                                        :undef => :replace)
-      texts << text
-      size += text.bytesize
-    end
+
     @entry._key = data.uri.to_s
     @entry.title = data[:title] || data[:subject] || @entry._key
     @entry.mime_type = data.mime_type
+
+    texts = []
+    size = 0
+    begin
+      extractor.extract(data) do |extracted_data|
+        text = extracted_data.body.encode(Encoding::UTF_8,
+                                          :invalid => :replace,
+                                          :undef => :replace)
+        texts << text
+        size += text.bytesize
+      end
+    rescue ChupaText::UnknownEncodingError => error
+      @entry.errors.add(:body, "unknown encoding: #{error.message}")
+      return false
+    rescue => error
+      message = "unknown error: #{error.class}: #{error.message}"
+      error.backtrace.each do |location|
+        message << "\n#{location}"
+      end
+      @entry.errors.add(:body, message)
+      return false
+    end
     @entry.texts = texts
     @entry.size = size
     @entry.save
-------------- next part --------------
HTML����������������������������...
下载 



More information about the Groonga-commit mailing list
Back to archive index