mirror of
https://github.com/penpot/penpot.git
synced 2025-05-07 20:35:53 +02:00
🐛 Add better error handling on upload image by url.
This commit is contained in:
parent
d0a8647186
commit
fc49674997
2 changed files with 13 additions and 1 deletions
|
@ -66,9 +66,18 @@
|
||||||
[info]
|
[info]
|
||||||
(= (:mtype info) "image/svg+xml"))
|
(= (:mtype info) "image/svg+xml"))
|
||||||
|
|
||||||
|
(defn- fetch-url
|
||||||
|
[url]
|
||||||
|
(try
|
||||||
|
(http/get! url {:as :byte-array})
|
||||||
|
(catch Exception e
|
||||||
|
(ex/raise :type :validation
|
||||||
|
:code :unable-to-access-to-url
|
||||||
|
:cause e))))
|
||||||
|
|
||||||
(defn- download-media
|
(defn- download-media
|
||||||
[{:keys [storage] :as cfg} url]
|
[{:keys [storage] :as cfg} url]
|
||||||
(let [result (http/get! url {:as :byte-array})
|
(let [result (fetch-url url)
|
||||||
data (:body result)
|
data (:body result)
|
||||||
mtype (get (:headers result) "content-type")
|
mtype (get (:headers result) "content-type")
|
||||||
format (cm/mtype->format mtype)]
|
format (cm/mtype->format mtype)]
|
||||||
|
|
|
@ -424,6 +424,9 @@
|
||||||
(= (:code error) :media-type-not-allowed)
|
(= (:code error) :media-type-not-allowed)
|
||||||
(rx/of (dm/error (tr "errors.media-type-not-allowed")))
|
(rx/of (dm/error (tr "errors.media-type-not-allowed")))
|
||||||
|
|
||||||
|
(= (:code error) :ubable-to-access-to-url)
|
||||||
|
(rx/of (dm/error (tr "errors.media-type-not-allowed")))
|
||||||
|
|
||||||
(= (:code error) :invalid-image)
|
(= (:code error) :invalid-image)
|
||||||
(rx/of (dm/error (tr "errors.media-type-not-allowed")))
|
(rx/of (dm/error (tr "errors.media-type-not-allowed")))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue