🐛 Add better error handling on upload image by url.

This commit is contained in:
Andrey Antukh 2021-02-09 17:16:30 +01:00 committed by Andrés Moya
parent d0a8647186
commit fc49674997
2 changed files with 13 additions and 1 deletions

View file

@ -66,9 +66,18 @@
[info]
(= (: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
[{:keys [storage] :as cfg} url]
(let [result (http/get! url {:as :byte-array})
(let [result (fetch-url url)
data (:body result)
mtype (get (:headers result) "content-type")
format (cm/mtype->format mtype)]