2015-06-18 43 views
1

我在我的项目中有一个clojure端点,它基本上更新了couchdb中的一个文档。在clojure中处理uncaught_exception

(^{PUT true 
 
     Path "/{id}" 
 
     Produces ["application/json"] 
 
     Consumes ["application/json"] 
 
     ApiOperation {:value "Update" :notes ""} 
 
     } 
 
    method_name [this 
 
        ^{PathParam "id"} id 
 
        body] 
 
    (require 'com.xx.x.xx.xx.xx-response) 
 
    (let [doc (json/read-json body)] 
 
     (if-let [valid-doc (validate doc)] 
 
     (try+ 
 
      (->> 
 
      (assoc valid-doc :modificationDate (Utilities/getCurrentDate)) 
 
      (couch/update-document dbs/xx-db) 
 
      (core/ok-response)) 
 
      (catch java.io.IOException ex 
 
       (log/error "line num 197") 
 
      ) 
 
      (catch java.lang.Exception ex 
 
      (log/error "line num 200"))) 
 
)))

此端点抛出一个500捕获的异常时,有不同之处的原因沿着文件冲突,这被在日志文件中记录。跟踪重定向具有敏感信息。 我添加了一个catch块来处理这个异常[clojure.lang.ExceptionInfo]。它没有工作。

我该如何处理?有没有办法去除痕迹重定向?

Request exception uncaught_exception Status 500 Message An exception was thrown that was not handled by the application or a provider. 
clojure.lang.ExceptionInfo: throw+: {:trace-redirects ["https://abc123xyz-dev:separate settled first [email protected]/1111"], :request-time 3899, :request {:path "/sss", :protocol "https", :scheme :https, :data nil, :http-url "https://abc123xyz-dev.cloudant.com/1111", :conn-timeout 6000, :host "abc123xyz-dev.cloudant.com", :follow-redirects true, :request-method :post, :query-string nil, :save-request? true, :anchor nil, :http-req #<HttpPost POST https://abc123xyz-dev.cloudant.com/1111 HTTP/1.1>, :as :json, :uri "/1111", :port -1, :username "abc123xyz-dev", :data-length nil, :server-name "abc123xyz-dev.cloudant.com", :headers {"authorization" "Basic bGl2ZW1vY2hhLWRldjpzZXXBhcmF0ZSBzZXR0bGVkI1ZpcnN0IGRlY111Ww=", "accept-encoding" "gzip, deflate", "content-type" "application/json", "user-agent" "com.ashafa.clutch/0.3.0", "accept" "*/*"}, :socket-timeout 6000, :body-type nil, :server-port nil, :query nil, :password "[email protected]"}, :status 400, :headers {"server" "CouchDB/1.0.2 (Erlang OTP/R14B)", "strict-transport-security" "max-age=31536000", "x-couch-request-id" "119df05d59", "content-type" "text/plain;charset=utf-8", "date" "Thu, 18 Jun 2015 17:46:08 GMT", "cache-control" "must-revalidate", "x-content-type-options" "nosniff;", "content-length" "54", "connection" "close"}, :body "{\"error\":\"bad_request\",\"reason\":\"invalid UTF-8 JSON\"}\n"} 

更新:道歉。即使在发布有效的json进行更新时也会发生此错误。对不起,如果这是误导。

  • 感谢

回答

0

看起来你需要你的try块是,如果你想赶上读取或验证JSON时抛出的异常得更高。

0

try+ 

呼叫应该来的

read-json 

函数调用之前。

所以:

 (^{PUT true 
      Path "/{id}" 
      Produces ["application/json"] 
      Consumes ["application/json"] 
      ApiOperation {:value "Update" :notes ""} 
      } 
      method_name [this 
          ^{PathParam "id"} id 
          body] 
      (require 'com.xx.x.xx.xx.xx-response) 
      (try+ 
      (let [doc (json/read-json body)] 
      (if-let [valid-doc (validate doc)] 
       (->> 
       (assoc valid-doc :modificationDate (Utilities/getCurrentDate)) 
       (couch/update-document dbs/xx-db) 
       (core/ok-response)) 
       )) 

      (catch java.io.IOException ex 
        (log/error "line num 197") 
       ) 
       (catch java.lang.Exception ex 
        (log/error "line num 200"))))