1#[derive(Debug, thiserror::Error)]
2#[error("{} {}", .code, .message)]
3pub struct Error {
4 pub code: u16,
5 pub message: String,
6}
7
8pub fn already_exists() -> Error {
9 Error {
10 code: 409,
11 message: "already exists".to_string(),
12 }
13}
14
15pub fn already_exists_with_message(msg: &str) -> Error {
16 Error {
17 code: 409,
18 message: msg.to_string(),
19 }
20}
21
22pub fn internal() -> Error {
23 Error {
24 code: 500,
25 message: "internal".to_string(),
26 }
27}
28
29pub fn internal_with_message(msg: &str) -> Error {
30 Error {
31 code: 500,
32 message: msg.to_string(),
33 }
34}
35
36pub fn invalid_argument() -> Error {
37 Error {
38 code: 400,
39 message: "invalid argument".to_string(),
40 }
41}
42
43pub fn invalid_argument_with_message(msg: &str) -> Error {
44 Error {
45 code: 400,
46 message: msg.to_string(),
47 }
48}
49
50pub fn not_found() -> Error {
51 Error {
52 code: 404,
53 message: "not found".to_string(),
54 }
55}
56
57pub fn not_found_with_message(msg: &str) -> Error {
58 Error {
59 code: 404,
60 message: msg.to_string(),
61 }
62}
63
64pub fn permission_denied() -> Error {
65 Error {
66 code: 403,
67 message: "permission denied".to_string(),
68 }
69}
70
71pub fn permission_denied_with_message(msg: &str) -> Error {
72 Error {
73 code: 403,
74 message: msg.to_string(),
75 }
76}
77
78pub fn unauthenticated() -> Error {
79 Error {
80 code: 401,
81 message: "unauthenticated".to_string(),
82 }
83}
84
85pub fn unauthenticated_with_message(msg: &str) -> Error {
86 Error {
87 code: 401,
88 message: msg.to_string(),
89 }
90}