Improve exception formating on backend

This commit is contained in:
Andrey Antukh 2022-11-28 16:47:27 +01:00
parent e43fc0feb0
commit 7f7efc5760
16 changed files with 224 additions and 82 deletions

View file

@ -41,7 +41,7 @@
(when-not (contains? cm/valid-image-types (.-type file))
(ex/raise :type :validation
:code :media-type-not-allowed
:hint (str/fmt "media type %s is not supported" (.-type file))))
:hint (str/ffmt "media type % is not supported" (.-type file))))
file)
(defn notify-start-loading

View file

@ -7,6 +7,7 @@
(ns app.main.data.workspace.svg-upload
(:require
[app.common.data :as d]
[app.common.spec :as us]
[app.common.exceptions :as ex]
[app.common.geom.matrix :as gmt]
[app.common.geom.point :as gpt]
@ -35,22 +36,24 @@
(defonce default-image {:x 0 :y 0 :width 1 :height 1 :rx 0 :ry 0})
(defn- assert-valid-num [attr num]
(when (or (not (d/num? num))
(>= num max-safe-int )
(<= num min-safe-int))
(ex/raise (str (d/name attr) " attribute invalid: " num)))
(us/verify!
:expr (and (d/num? num)
(<= num max-safe-int)
(>= num min-safe-int))
:hint (str/ffmt "%1 attribute has invalid value: %2" (d/name attr) num))
;; If the number is between 0-1 we round to 1 (same in negative form
(cond
(and (> num 0) (< num 1)) 1
(and (< num 0) (> num -1)) -1
:else num))
(and (> num 0) (< num 1)) 1
(and (< num 0) (> num -1)) -1
:else num))
(defn- assert-valid-pos-num [attr num]
(let [num (assert-valid-num attr num)]
(when (< num 0)
(ex/raise (str (d/name attr) " attribute invalid: " num)))
num))
(defn- assert-valid-pos-num
[attr num]
(us/verify!
:expr (pos? num)
:hint (str/ffmt "%1 attribute should be positive" (d/name attr)))
num)
(defn- svg-dimensions [data]
(let [width (get-in data [:attrs :width] 100)

View file

@ -162,7 +162,7 @@
[[r g b]]
(cond
(and (= 255 r) (= 255 g) (= 255 b))
(ex/raise "Cannot get next color")
(throw (ex-info "cannot get next color" {:r r :g g :b b}))
(and (= 255 g) (= 255 b))
[(inc r) 0 0]