-
Notifications
You must be signed in to change notification settings - Fork 3
/
exception_util.clj
38 lines (31 loc) · 1.42 KB
/
exception_util.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
(ns clojure-commons.exception-util
(:use [slingshot.slingshot :only [throw+]])
(:require [clojure-commons.exception :as cx]))
(defn unauthorized
"Throws an error indicating that the request is unauthorized."
[reason & {:as ex-info}]
(throw+ (assoc ex-info :type ::cx/authentication-not-found :error reason)))
(defn forbidden
"Throws an error indicating that the request is forbidden."
[reason & {:as ex-info}]
(throw+ (assoc ex-info :type ::cx/forbidden :error reason)))
(defn exists
"Throws an error indicating that there was an attempt to create something that already exists."
[reason & {:as ex-info}]
(throw+ (assoc ex-info :type ::cx/exists :error reason)))
(defn bad-request
"Throws an error indicating that that a bad request was received."
[reason & {:as ex-info}]
(throw+ (assoc ex-info :type ::cx/bad-request :error reason)))
(defn illegal-argument
"Throws an error indicating that that a bad request argument was received."
[reason & {:as ex-info}]
(throw+ (assoc ex-info :type ::cx/illegal-argument :error reason)))
(defn not-found
"Throws an error indicating that a resource could not be found."
[reason & {:as ex-info}]
(throw+ (assoc ex-info :type ::cx/not-found :error reason)))
(defn internal-system-error
"Throws an error explicitly indicating that an internal system error occurred."
[reason & {:as ex-info}]
(throw+ (assoc ex-info :type ::cx/internal-system-error :error reason)))