@@ -68,7 +68,7 @@ impl From<&str> for Error {
6868#[ macro_export]
6969macro_rules! http_error {
7070 ( $( $arg: tt) * ) => { {
71- Error :: from_err ( anyhow:: anyhow!( $( $arg) * ) , None )
71+ $crate :: Error :: from ( anyhow:: anyhow!( $( $arg) * ) )
7272 } }
7373}
7474
@@ -77,143 +77,143 @@ macro_rules! http_error {
7777#[ macro_export]
7878macro_rules! bad_request {
7979 ( $( $arg: tt) * ) => { {
80- Error :: from_err ( anyhow:: anyhow!( $( $arg) * ) , Some ( StatusCode :: BAD_REQUEST ) )
80+ $crate :: Error :: from ( anyhow:: anyhow!( $( $arg) * ) ) . with_status ( Some ( 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]
8686macro_rules! unauthorized {
8787 ( $( $arg: tt) * ) => { {
88- Error :: from_err ( anyhow:: anyhow!( $( $arg) * ) , Some ( StatusCode :: UNAUTHORIZED ) )
88+ $crate :: Error :: from ( anyhow:: anyhow!( $( $arg) * ) ) . with_status ( Some ( 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]
9494macro_rules! payment_required {
9595 ( $( $arg: tt) * ) => { {
96- Error :: from_err ( anyhow:: anyhow!( $( $arg) * ) , Some ( StatusCode :: PAYMENT_REQUIRED ) )
96+ $crate :: Error :: from ( anyhow:: anyhow!( $( $arg) * ) ) . with_status ( Some ( 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]
102102macro_rules! forbidden {
103103 ( $( $arg: tt) * ) => { {
104- Error :: from_err ( anyhow:: anyhow!( $( $arg) * ) , Some ( StatusCode :: FORBIDDEN ) )
104+ $crate :: Error :: from ( anyhow:: anyhow!( $( $arg) * ) ) . with_status ( Some ( 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]
110110macro_rules! not_found {
111111 ( $( $arg: tt) * ) => { {
112- Error :: from_err ( anyhow:: anyhow!( $( $arg) * ) , Some ( StatusCode :: NOT_FOUND ) )
112+ $crate :: Error :: from ( anyhow:: anyhow!( $( $arg) * ) ) . with_status ( Some ( 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]
118118macro_rules! method_not_allowed {
119119 ( $( $arg: tt) * ) => { {
120- Error :: from_err ( anyhow:: anyhow!( $( $arg) * ) , Some ( StatusCode :: METHOD_NOT_ALLOWED ) )
120+ $crate :: Error :: from ( anyhow:: anyhow!( $( $arg) * ) ) . with_status ( Some ( 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]
126126macro_rules! not_acceptable {
127127 ( $( $arg: tt) * ) => { {
128- Error :: from_err ( anyhow:: anyhow!( $( $arg) * ) , Some ( StatusCode :: NOT_ACCEPTABLE ) )
128+ $crate :: Error :: from ( anyhow:: anyhow!( $( $arg) * ) ) . with_status ( Some ( 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]
134134macro_rules! proxy_authentication_required {
135135 ( $( $arg: tt) * ) => { {
136- Error :: from_err ( anyhow:: anyhow!( $( $arg) * ) , Some ( StatusCode :: PROXY_AUTHENTICATION_REQUIRED ) )
136+ $crate :: Error :: from ( anyhow:: anyhow!( $( $arg) * ) ) . with_status ( Some ( 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]
142142macro_rules! request_timeout {
143143 ( $( $arg: tt) * ) => { {
144- Error :: from_err ( anyhow:: anyhow!( $( $arg) * ) , Some ( StatusCode :: REQUEST_TIMEOUT ) )
144+ $crate :: Error :: from ( anyhow:: anyhow!( $( $arg) * ) ) . with_status ( Some ( 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]
150150macro_rules! conflict {
151151 ( $( $arg: tt) * ) => { {
152- Error :: from_err ( anyhow:: anyhow!( $( $arg) * ) , Some ( StatusCode :: CONFLICT ) )
152+ $crate :: Error :: from ( anyhow:: anyhow!( $( $arg) * ) ) . with_status ( Some ( StatusCode :: CONFLICT ) )
153153 } }
154154}
155155
156156/// Construct an `Error` with `StatusCode::GONE` from a string or existing non-anyhow error value.
157157#[ macro_export]
158158macro_rules! gone {
159159 ( $( $arg: tt) * ) => { {
160- Error :: from_err ( anyhow:: anyhow!( $( $arg) * ) , Some ( StatusCode :: GONE ) )
160+ $crate :: Error :: from ( anyhow:: anyhow!( $( $arg) * ) ) . with_status ( Some ( 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]
166166macro_rules! length_required {
167167 ( $( $arg: tt) * ) => { {
168- Error :: from_err ( anyhow:: anyhow!( $( $arg) * ) , Some ( StatusCode :: LENGTH_REQUIRED ) )
168+ $crate :: Error :: from ( anyhow:: anyhow!( $( $arg) * ) ) . with_status ( Some ( 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]
174174macro_rules! precondition_failed {
175175 ( $( $arg: tt) * ) => { {
176- Error :: from_err ( anyhow:: anyhow!( $( $arg) * ) , Some ( StatusCode :: PRECONDITION_FAILED ) )
176+ $crate :: Error :: from ( anyhow:: anyhow!( $( $arg) * ) ) . with_status ( Some ( 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]
182182macro_rules! payload_too_large {
183183 ( $( $arg: tt) * ) => { {
184- Error :: from_err ( anyhow:: anyhow!( $( $arg) * ) , Some ( StatusCode :: PAYLOAD_TOO_LARGE ) )
184+ $crate :: Error :: from ( anyhow:: anyhow!( $( $arg) * ) ) . with_status ( Some ( 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]
190190macro_rules! uri_too_long {
191191 ( $( $arg: tt) * ) => { {
192- Error :: from_err ( anyhow:: anyhow!( $( $arg) * ) , Some ( StatusCode :: URI_TOO_LONG ) )
192+ $crate :: Error :: from ( anyhow:: anyhow!( $( $arg) * ) ) . with_status ( Some ( 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]
198198macro_rules! unsupported_media_type {
199199 ( $( $arg: tt) * ) => { {
200- Error :: from_err ( anyhow:: anyhow!( $( $arg) * ) , Some ( StatusCode :: UNSUPPORTED_MEDIA_TYPE ) )
200+ $crate :: Error :: from ( anyhow:: anyhow!( $( $arg) * ) ) . with_status ( Some ( 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]
206206macro_rules! range_not_satisfiable {
207207 ( $( $arg: tt) * ) => { {
208- Error :: from_err ( anyhow:: anyhow!( $( $arg) * ) , Some ( StatusCode :: RANGE_NOT_SATISFIABLE ) )
208+ $crate :: Error :: from ( anyhow:: anyhow!( $( $arg) * ) ) . with_status ( Some ( 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]
214214macro_rules! expectation_failed {
215215 ( $( $arg: tt) * ) => { {
216- Error :: from_err ( anyhow:: anyhow!( $( $arg) * ) , Some ( StatusCode :: EXPECTATION_FAILED ) )
216+ $crate :: Error :: from ( anyhow:: anyhow!( $( $arg) * ) ) . with_status ( Some ( StatusCode :: EXPECTATION_FAILED ) )
217217 } }
218218}
219219
@@ -222,70 +222,70 @@ macro_rules! expectation_failed {
222222#[ macro_export]
223223macro_rules! internal_server_error {
224224 ( $( $arg: tt) * ) => { {
225- Error :: from_err ( anyhow:: anyhow!( $( $arg) * ) , Some ( StatusCode :: INTERNAL_SERVER_ERROR ) )
225+ $crate :: Error :: from ( anyhow:: anyhow!( $( $arg) * ) ) . with_status ( Some ( 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]
231231macro_rules! not_implemented {
232232 ( $( $arg: tt) * ) => { {
233- Error :: from_err ( anyhow:: anyhow!( $( $arg) * ) , Some ( StatusCode :: NOT_IMPLEMENTED ) )
233+ $crate :: Error :: from ( anyhow:: anyhow!( $( $arg) * ) ) . with_status ( Some ( 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]
239239macro_rules! bad_gateway {
240240 ( $( $arg: tt) * ) => { {
241- Error :: from_err ( anyhow:: anyhow!( $( $arg) * ) , Some ( StatusCode :: BAD_GATEWAY ) )
241+ $crate :: Error :: from ( anyhow:: anyhow!( $( $arg) * ) ) . with_status ( Some ( 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]
247247macro_rules! service_unavailable {
248248 ( $( $arg: tt) * ) => { {
249- Error :: from_err ( anyhow:: anyhow!( $( $arg) * ) , Some ( StatusCode :: SERVICE_UNAVAILABLE ) )
249+ $crate :: Error :: from ( anyhow:: anyhow!( $( $arg) * ) ) . with_status ( Some ( 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]
255255macro_rules! gateway_timeout {
256256 ( $( $arg: tt) * ) => { {
257- Error :: from_err ( anyhow:: anyhow!( $( $arg) * ) , Some ( StatusCode :: GATEWAY_TIMEOUT ) )
257+ Error :: from ( anyhow:: anyhow!( $( $arg) * ) ) . with_status ( Some ( 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]
263263macro_rules! http_version_not_supported {
264264 ( $( $arg: tt) * ) => { {
265- Error :: from_err ( anyhow:: anyhow!( $( $arg) * ) , Some ( StatusCode :: HTTP_VERSION_NOT_SUPPORTED ) )
265+ Error :: from ( anyhow:: anyhow!( $( $arg) * ) ) . with_status ( Some ( 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]
271271macro_rules! variant_also_negotiates {
272272 ( $( $arg: tt) * ) => { {
273- Error :: from_err ( anyhow:: anyhow!( $( $arg) * ) , Some ( StatusCode :: VARIANT_ALSO_NEGOTIATES ) )
273+ Error :: from ( anyhow:: anyhow!( $( $arg) * ) ) . with_status ( Some ( 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]
279279macro_rules! insufficient_storage {
280280 ( $( $arg: tt) * ) => { {
281- Error :: from_err ( anyhow:: anyhow!( $( $arg) * ) , Some ( StatusCode :: INSUFFICIENT_STORAGE ) )
281+ Error :: from ( anyhow:: anyhow!( $( $arg) * ) ) . with_status ( Some ( 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]
287287macro_rules! loop_detected {
288288 ( $( $arg: tt) * ) => { {
289- Error :: from_err ( anyhow:: anyhow!( $( $arg) * ) , Some ( StatusCode :: LOOP_DETECTED ) )
289+ Error :: from ( anyhow:: anyhow!( $( $arg) * ) ) . with_status ( Some ( StatusCode :: LOOP_DETECTED ) )
290290 } }
291291}
0 commit comments