0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-14 11:09:04 -05:00

🐛 Fix incorrect frontend error handling on import code

This commit is contained in:
Andrey Antukh 2023-11-11 00:11:36 +01:00
parent 9b3964e6d7
commit d5e34df364

View file

@ -14,6 +14,7 @@
[app.common.geom.shapes.path :as gpa] [app.common.geom.shapes.path :as gpa]
[app.common.logging :as log] [app.common.logging :as log]
[app.common.media :as cm] [app.common.media :as cm]
[app.common.pprint :as pp]
[app.common.text :as ct] [app.common.text :as ct]
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
[app.main.repo :as rp] [app.main.repo :as rp]
@ -639,6 +640,7 @@
(let [error (or (.-message data) (tr "dashboard.import.analyze-error"))] (let [error (or (.-message data) (tr "dashboard.import.analyze-error"))]
(rx/of {:uri (:uri file) :error error})))))))))) (rx/of {:uri (:uri file) :error error}))))))))))
(defmethod impl/handler :import-files (defmethod impl/handler :import-files
[{:keys [project-id files features]}] [{:keys [project-id files features]}]
@ -648,7 +650,7 @@
zip-files (filter #(= "application/zip" (:type %)) files) zip-files (filter #(= "application/zip" (:type %)) files)
binary-files (filter #(= "application/octet-stream" (:type %)) files)] binary-files (filter #(= "application/octet-stream" (:type %)) files)]
(->> (rx/merge (rx/merge
(->> (create-files context zip-files) (->> (create-files context zip-files)
(rx/flat-map (rx/flat-map
(fn [[file data]] (fn [[file data]]
@ -667,7 +669,9 @@
:errors (:errors file) :errors (:errors file)
:file-id (:file-id data)}))))))) :file-id (:file-id data)})))))))
(rx/catch (fn [cause] (rx/catch (fn [cause]
(log/error :hint (ex-message cause) :file-id (:file-id data) :cause cause) (log/error :hint (ex-message cause)
:file-id (:file-id data)
:cause cause)
(rx/of {:status :import-error (rx/of {:status :import-error
:file-id (:file-id data) :file-id (:file-id data)
:error (ex-message cause) :error (ex-message cause)
@ -681,19 +685,25 @@
:response-type :blob :response-type :blob
:method :get}) :method :get})
(rx/map :body) (rx/map :body)
(rx/mapcat #(rp/cmd! :import-binfile {:file % (rx/mapcat #(rp/cmd! :import-binfile {:file % :project-id project-id}))
:project-id project-id})) (rx/map (fn [_]
(rx/map
(fn [_]
{:status :import-finish {:status :import-finish
:file-id (:file-id data)}))))))) :file-id (:file-id data)}))
(rx/catch (fn [cause] (rx/catch (fn [cause]
(log/error :hint "unexpected error on import process" (log/error :hint "unexpected error on import process"
:project-id project-id :project-id project-id
:cause cause) ::log/sync? true)
(if (map? cause) ;; TODO: consider do thi son logging directly ?
(js/console.error (pr-str cause))
(js/console.error cause)))))))
(when (map? cause)
(println "Error data:")
(pp/pprint (dissoc cause :explain) {:level 2 :length 10}))
(when (string? (:explain cause))
(js/console.log (:explain cause)))
(rx/of {:status :import-error
:file-id (:file-id data)
:error (:hint cause)
:error-data cause}))))))))))