Skip to content

Commit 9f0861e

Browse files
committed
refactor: remove option of http error macros
1 parent 30bc906 commit 9f0861e

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

src/error.rs

+27-27
Original file line numberDiff line numberDiff line change
@@ -77,143 +77,143 @@ macro_rules! http_error {
7777
#[macro_export]
7878
macro_rules! bad_request {
7979
($($arg:tt)*) => {{
80-
$crate::Error::from(anyhow::anyhow!($($arg)*)).with_status(Some(StatusCode::BAD_REQUEST))
80+
$crate::Error::from(anyhow::anyhow!($($arg)*)).with_status(StatusCode::BAD_REQUEST)
8181
}}
8282
}
8383

8484
/// Construct an `Error` with `StatusCode::UNAUTHORIZED` from a string or existing non-anyhow error value.
8585
#[macro_export]
8686
macro_rules! unauthorized {
8787
($($arg:tt)*) => {{
88-
$crate::Error::from(anyhow::anyhow!($($arg)*)).with_status(Some(StatusCode::UNAUTHORIZED))
88+
$crate::Error::from(anyhow::anyhow!($($arg)*)).with_status(StatusCode::UNAUTHORIZED)
8989
}}
9090
}
9191

9292
/// Construct an `Error` with `StatusCode::PAYMENT_REQUIRED` from a string or existing non-anyhow error value.
9393
#[macro_export]
9494
macro_rules! payment_required {
9595
($($arg:tt)*) => {{
96-
$crate::Error::from(anyhow::anyhow!($($arg)*)).with_status(Some(StatusCode::PAYMENT_REQUIRED))
96+
$crate::Error::from(anyhow::anyhow!($($arg)*)).with_status(StatusCode::PAYMENT_REQUIRED)
9797
}}
9898
}
9999

100100
/// Construct an `Error` with `StatusCode::FORBIDDEN` from a string or existing non-anyhow error value.
101101
#[macro_export]
102102
macro_rules! forbidden {
103103
($($arg:tt)*) => {{
104-
$crate::Error::from(anyhow::anyhow!($($arg)*)).with_status(Some(StatusCode::FORBIDDEN))
104+
$crate::Error::from(anyhow::anyhow!($($arg)*)).with_status(StatusCode::FORBIDDEN)
105105
}}
106106
}
107107

108108
/// Construct an `Error` with `StatusCode::NOT_FOUND` from a string or existing non-anyhow error value.
109109
#[macro_export]
110110
macro_rules! not_found {
111111
($($arg:tt)*) => {{
112-
$crate::Error::from(anyhow::anyhow!($($arg)*)).with_status(Some(StatusCode::NOT_FOUND))
112+
$crate::Error::from(anyhow::anyhow!($($arg)*)).with_status(StatusCode::NOT_FOUND)
113113
}}
114114
}
115115

116116
/// Construct an `Error` with `StatusCode::METHOD_NOT_ALLOWED` from a string or existing non-anyhow error value.
117117
#[macro_export]
118118
macro_rules! method_not_allowed {
119119
($($arg:tt)*) => {{
120-
$crate::Error::from(anyhow::anyhow!($($arg)*)).with_status(Some(StatusCode::METHOD_NOT_ALLOWED))
120+
$crate::Error::from(anyhow::anyhow!($($arg)*)).with_status(StatusCode::METHOD_NOT_ALLOWED)
121121
}}
122122
}
123123

124124
/// Construct an `Error` with `StatusCode::NOT_ACCEPTABLE` from a string or existing non-anyhow error value.
125125
#[macro_export]
126126
macro_rules! not_acceptable {
127127
($($arg:tt)*) => {{
128-
$crate::Error::from(anyhow::anyhow!($($arg)*)).with_status(Some(StatusCode::NOT_ACCEPTABLE))
128+
$crate::Error::from(anyhow::anyhow!($($arg)*)).with_status(StatusCode::NOT_ACCEPTABLE)
129129
}}
130130
}
131131

132132
/// Construct an `Error` with `StatusCode::PROXY_AUTHENTICATION_REQUIRED` from a string or existing non-anyhow error value.
133133
#[macro_export]
134134
macro_rules! proxy_authentication_required {
135135
($($arg:tt)*) => {{
136-
$crate::Error::from(anyhow::anyhow!($($arg)*)).with_status(Some(StatusCode::PROXY_AUTHENTICATION_REQUIRED))
136+
$crate::Error::from(anyhow::anyhow!($($arg)*)).with_status(StatusCode::PROXY_AUTHENTICATION_REQUIRED)
137137
}}
138138
}
139139

140140
/// Construct an `Error` with `StatusCode::REQUEST_TIMEOUT` from a string or existing non-anyhow error value.
141141
#[macro_export]
142142
macro_rules! request_timeout {
143143
($($arg:tt)*) => {{
144-
$crate::Error::from(anyhow::anyhow!($($arg)*)).with_status(Some(StatusCode::REQUEST_TIMEOUT))
144+
$crate::Error::from(anyhow::anyhow!($($arg)*)).with_status(StatusCode::REQUEST_TIMEOUT)
145145
}}
146146
}
147147

148148
/// Construct an `Error` with `StatusCode::CONFLICT` from a string or existing non-anyhow error value.
149149
#[macro_export]
150150
macro_rules! conflict {
151151
($($arg:tt)*) => {{
152-
$crate::Error::from(anyhow::anyhow!($($arg)*)).with_status(Some(StatusCode::CONFLICT))
152+
$crate::Error::from(anyhow::anyhow!($($arg)*)).with_status(StatusCode::CONFLICT)
153153
}}
154154
}
155155

156156
/// Construct an `Error` with `StatusCode::GONE` from a string or existing non-anyhow error value.
157157
#[macro_export]
158158
macro_rules! gone {
159159
($($arg:tt)*) => {{
160-
$crate::Error::from(anyhow::anyhow!($($arg)*)).with_status(Some(StatusCode::GONE))
160+
$crate::Error::from(anyhow::anyhow!($($arg)*)).with_status(StatusCode::GONE)
161161
}}
162162
}
163163

164164
/// Construct an `Error` with `StatusCode::LENGTH_REQUIRED` from a string or existing non-anyhow error value.
165165
#[macro_export]
166166
macro_rules! length_required {
167167
($($arg:tt)*) => {{
168-
$crate::Error::from(anyhow::anyhow!($($arg)*)).with_status(Some(StatusCode::LENGTH_REQUIRED))
168+
$crate::Error::from(anyhow::anyhow!($($arg)*)).with_status(StatusCode::LENGTH_REQUIRED)
169169
}}
170170
}
171171

172172
/// Construct an `Error` with `StatusCode::PRECONDITION_FAILED` from a string or existing non-anyhow error value.
173173
#[macro_export]
174174
macro_rules! precondition_failed {
175175
($($arg:tt)*) => {{
176-
$crate::Error::from(anyhow::anyhow!($($arg)*)).with_status(Some(StatusCode::PRECONDITION_FAILED))
176+
$crate::Error::from(anyhow::anyhow!($($arg)*)).with_status(StatusCode::PRECONDITION_FAILED)
177177
}}
178178
}
179179

180180
/// Construct an `Error` with `StatusCode::PAYLOAD_TOO_LARGE` from a string or existing non-anyhow error value.
181181
#[macro_export]
182182
macro_rules! payload_too_large {
183183
($($arg:tt)*) => {{
184-
$crate::Error::from(anyhow::anyhow!($($arg)*)).with_status(Some(StatusCode::PAYLOAD_TOO_LARGE))
184+
$crate::Error::from(anyhow::anyhow!($($arg)*)).with_status(StatusCode::PAYLOAD_TOO_LARGE)
185185
}}
186186
}
187187

188188
/// Construct an `Error` with `StatusCode::URI_TOO_LONG` from a string or existing non-anyhow error value.
189189
#[macro_export]
190190
macro_rules! uri_too_long {
191191
($($arg:tt)*) => {{
192-
$crate::Error::from(anyhow::anyhow!($($arg)*)).with_status(Some(StatusCode::URI_TOO_LONG))
192+
$crate::Error::from(anyhow::anyhow!($($arg)*)).with_status(StatusCode::URI_TOO_LONG)
193193
}}
194194
}
195195

196196
/// Construct an `Error` with `StatusCode::UNSUPPORTED_MEDIA_TYPE` from a string or existing non-anyhow error value.
197197
#[macro_export]
198198
macro_rules! unsupported_media_type {
199199
($($arg:tt)*) => {{
200-
$crate::Error::from(anyhow::anyhow!($($arg)*)).with_status(Some(StatusCode::UNSUPPORTED_MEDIA_TYPE))
200+
$crate::Error::from(anyhow::anyhow!($($arg)*)).with_status(StatusCode::UNSUPPORTED_MEDIA_TYPE)
201201
}}
202202
}
203203

204204
/// Construct an `Error` with `StatusCode::RANGE_NOT_SATISFIABLE` from a string or existing non-anyhow error value.
205205
#[macro_export]
206206
macro_rules! range_not_satisfiable {
207207
($($arg:tt)*) => {{
208-
$crate::Error::from(anyhow::anyhow!($($arg)*)).with_status(Some(StatusCode::RANGE_NOT_SATISFIABLE))
208+
$crate::Error::from(anyhow::anyhow!($($arg)*)).with_status(StatusCode::RANGE_NOT_SATISFIABLE)
209209
}}
210210
}
211211

212212
/// Construct an `Error` with `StatusCode::EXPECTATION_FAILED` from a string or existing non-anyhow error value.
213213
#[macro_export]
214214
macro_rules! expectation_failed {
215215
($($arg:tt)*) => {{
216-
$crate::Error::from(anyhow::anyhow!($($arg)*)).with_status(Some(StatusCode::EXPECTATION_FAILED))
216+
$crate::Error::from(anyhow::anyhow!($($arg)*)).with_status(StatusCode::EXPECTATION_FAILED)
217217
}}
218218
}
219219

@@ -222,70 +222,70 @@ macro_rules! expectation_failed {
222222
#[macro_export]
223223
macro_rules! internal_server_error {
224224
($($arg:tt)*) => {{
225-
$crate::Error::from(anyhow::anyhow!($($arg)*)).with_status(Some(StatusCode::INTERNAL_SERVER_ERROR))
225+
$crate::Error::from(anyhow::anyhow!($($arg)*)).with_status(StatusCode::INTERNAL_SERVER_ERROR)
226226
}}
227227
}
228228

229229
/// Construct an `Error` with `StatusCode::NOT_IMPLEMENTED` from a string or existing non-anyhow error value.
230230
#[macro_export]
231231
macro_rules! not_implemented {
232232
($($arg:tt)*) => {{
233-
$crate::Error::from(anyhow::anyhow!($($arg)*)).with_status(Some(StatusCode::NOT_IMPLEMENTED))
233+
$crate::Error::from(anyhow::anyhow!($($arg)*)).with_status(StatusCode::NOT_IMPLEMENTED)
234234
}}
235235
}
236236

237237
/// Construct an `Error` with `StatusCode::BAD_GATEWAY` from a string or existing non-anyhow error value.
238238
#[macro_export]
239239
macro_rules! bad_gateway {
240240
($($arg:tt)*) => {{
241-
$crate::Error::from(anyhow::anyhow!($($arg)*)).with_status(Some(StatusCode::BAD_GATEWAY))
241+
$crate::Error::from(anyhow::anyhow!($($arg)*)).with_status(StatusCode::BAD_GATEWAY)
242242
}}
243243
}
244244

245245
/// Construct an `Error` with `StatusCode::SERVICE_UNAVAILABLE` from a string or existing non-anyhow error value.
246246
#[macro_export]
247247
macro_rules! service_unavailable {
248248
($($arg:tt)*) => {{
249-
$crate::Error::from(anyhow::anyhow!($($arg)*)).with_status(Some(StatusCode::SERVICE_UNAVAILABLE))
249+
$crate::Error::from(anyhow::anyhow!($($arg)*)).with_status(StatusCode::SERVICE_UNAVAILABLE)
250250
}}
251251
}
252252

253253
/// Construct an `Error` with `StatusCode::GATEWAY_TIMEOUT` from a string or existing non-anyhow error value.
254254
#[macro_export]
255255
macro_rules! gateway_timeout {
256256
($($arg:tt)*) => {{
257-
Error::from(anyhow::anyhow!($($arg)*)).with_status(Some(StatusCode::GATEWAY_TIMEOUT))
257+
Error::from(anyhow::anyhow!($($arg)*)).with_status(StatusCode::GATEWAY_TIMEOUT)
258258
}}
259259
}
260260

261261
/// Construct an `Error` with `StatusCode::HTTP_VERSION_NOT_SUPPORTED` from a string or existing non-anyhow error value.
262262
#[macro_export]
263263
macro_rules! http_version_not_supported {
264264
($($arg:tt)*) => {{
265-
Error::from(anyhow::anyhow!($($arg)*)).with_status(Some(StatusCode::HTTP_VERSION_NOT_SUPPORTED))
265+
Error::from(anyhow::anyhow!($($arg)*)).with_status(StatusCode::HTTP_VERSION_NOT_SUPPORTED)
266266
}}
267267
}
268268

269269
/// Construct an `Error` with `StatusCode::VARIANT_ALSO_NEGOTIATES` from a string or existing non-anyhow error value.
270270
#[macro_export]
271271
macro_rules! variant_also_negotiates {
272272
($($arg:tt)*) => {{
273-
Error::from(anyhow::anyhow!($($arg)*)).with_status(Some(StatusCode::VARIANT_ALSO_NEGOTIATES))
273+
Error::from(anyhow::anyhow!($($arg)*)).with_status(StatusCode::VARIANT_ALSO_NEGOTIATES)
274274
}}
275275
}
276276

277277
/// Construct an `Error` with `StatusCode::INSUFFICIENT_STORAGE` from a string or existing non-anyhow error value.
278278
#[macro_export]
279279
macro_rules! insufficient_storage {
280280
($($arg:tt)*) => {{
281-
Error::from(anyhow::anyhow!($($arg)*)).with_status(Some(StatusCode::INSUFFICIENT_STORAGE))
281+
Error::from(anyhow::anyhow!($($arg)*)).with_status(StatusCode::INSUFFICIENT_STORAGE)
282282
}}
283283
}
284284

285285
/// Construct an `Error` with `StatusCode::LOOP_DETECTED` from a string or existing non-anyhow error value.
286286
#[macro_export]
287287
macro_rules! loop_detected {
288288
($($arg:tt)*) => {{
289-
Error::from(anyhow::anyhow!($($arg)*)).with_status(Some(StatusCode::LOOP_DETECTED))
289+
Error::from(anyhow::anyhow!($($arg)*)).with_status(StatusCode::LOOP_DETECTED)
290290
}}
291291
}

0 commit comments

Comments
 (0)