@@ -8,6 +8,8 @@ use crate::request::Request;
8
8
use crate :: http:: { Status , ContentType , uri} ;
9
9
use crate :: catcher:: { Handler , BoxFuture } ;
10
10
11
+ use super :: ErasedErrorRef ;
12
+
11
13
/// An error catching route.
12
14
///
13
15
/// Catchers are routes that run when errors are produced by the application.
@@ -147,20 +149,20 @@ impl Catcher {
147
149
///
148
150
/// ```rust
149
151
/// use rocket::request::Request;
150
- /// use rocket::catcher::{Catcher, BoxFuture};
152
+ /// use rocket::catcher::{Catcher, BoxFuture, ErasedErrorRef };
151
153
/// use rocket::response::Responder;
152
154
/// use rocket::http::Status;
153
155
///
154
- /// fn handle_404<'r>(status: Status, req: &'r Request<'_>) -> BoxFuture<'r> {
156
+ /// fn handle_404<'r>(status: Status, req: &'r Request<'_>, _e: &ErasedErrorRef<'r> ) -> BoxFuture<'r> {
155
157
/// let res = (status, format!("404: {}", req.uri()));
156
158
/// Box::pin(async move { res.respond_to(req) })
157
159
/// }
158
160
///
159
- /// fn handle_500<'r>(_: Status, req: &'r Request<'_>) -> BoxFuture<'r> {
161
+ /// fn handle_500<'r>(_: Status, req: &'r Request<'_>, _e: &ErasedErrorRef<'r> ) -> BoxFuture<'r> {
160
162
/// Box::pin(async move{ "Whoops, we messed up!".respond_to(req) })
161
163
/// }
162
164
///
163
- /// fn handle_default<'r>(status: Status, req: &'r Request<'_>) -> BoxFuture<'r> {
165
+ /// fn handle_default<'r>(status: Status, req: &'r Request<'_>, _e: &ErasedErrorRef<'r> ) -> BoxFuture<'r> {
164
166
/// let res = (status, format!("{}: {}", status, req.uri()));
165
167
/// Box::pin(async move { res.respond_to(req) })
166
168
/// }
@@ -199,11 +201,11 @@ impl Catcher {
199
201
///
200
202
/// ```rust
201
203
/// use rocket::request::Request;
202
- /// use rocket::catcher::{Catcher, BoxFuture};
204
+ /// use rocket::catcher::{Catcher, BoxFuture, ErasedErrorRef };
203
205
/// use rocket::response::Responder;
204
206
/// use rocket::http::Status;
205
207
///
206
- /// fn handle_404<'r>(status: Status, req: &'r Request<'_>) -> BoxFuture<'r> {
208
+ /// fn handle_404<'r>(status: Status, req: &'r Request<'_>, _e: &ErasedErrorRef<'r> ) -> BoxFuture<'r> {
207
209
/// let res = (status, format!("404: {}", req.uri()));
208
210
/// Box::pin(async move { res.respond_to(req) })
209
211
/// }
@@ -225,12 +227,12 @@ impl Catcher {
225
227
///
226
228
/// ```rust
227
229
/// use rocket::request::Request;
228
- /// use rocket::catcher::{Catcher, BoxFuture};
230
+ /// use rocket::catcher::{Catcher, BoxFuture, ErasedErrorRef };
229
231
/// use rocket::response::Responder;
230
232
/// use rocket::http::Status;
231
233
/// # use rocket::uri;
232
234
///
233
- /// fn handle_404<'r>(status: Status, req: &'r Request<'_>) -> BoxFuture<'r> {
235
+ /// fn handle_404<'r>(status: Status, req: &'r Request<'_>, _e: &ErasedErrorRef<'r> ) -> BoxFuture<'r> {
234
236
/// let res = (status, format!("404: {}", req.uri()));
235
237
/// Box::pin(async move { res.respond_to(req) })
236
238
/// }
@@ -279,11 +281,11 @@ impl Catcher {
279
281
///
280
282
/// ```rust
281
283
/// use rocket::request::Request;
282
- /// use rocket::catcher::{Catcher, BoxFuture};
284
+ /// use rocket::catcher::{Catcher, BoxFuture, ErasedErrorRef };
283
285
/// use rocket::response::Responder;
284
286
/// use rocket::http::Status;
285
287
///
286
- /// fn handle_404<'r>(status: Status, req: &'r Request<'_>) -> BoxFuture<'r> {
288
+ /// fn handle_404<'r>(status: Status, req: &'r Request<'_>, _e: &ErasedErrorRef<'r> ) -> BoxFuture<'r> {
287
289
/// let res = (status, format!("404: {}", req.uri()));
288
290
/// Box::pin(async move { res.respond_to(req) })
289
291
/// }
@@ -313,7 +315,7 @@ impl Catcher {
313
315
314
316
impl Default for Catcher {
315
317
fn default ( ) -> Self {
316
- fn handler < ' r > ( s : Status , req : & ' r Request < ' _ > ) -> BoxFuture < ' r > {
318
+ fn handler < ' r > ( s : Status , req : & ' r Request < ' _ > , _e : & ErasedErrorRef < ' r > ) -> BoxFuture < ' r > {
317
319
Box :: pin ( async move { Ok ( default_handler ( s, req) ) } )
318
320
}
319
321
@@ -331,7 +333,7 @@ pub struct StaticInfo {
331
333
/// The catcher's status code.
332
334
pub code : Option < u16 > ,
333
335
/// The catcher's handler, i.e, the annotated function.
334
- pub handler : for <' r > fn ( Status , & ' r Request < ' _ > ) -> BoxFuture < ' r > ,
336
+ pub handler : for <' r > fn ( Status , & ' r Request < ' _ > , & ErasedErrorRef < ' r > ) -> BoxFuture < ' r > ,
335
337
/// The file, line, and column where the catcher was defined.
336
338
pub location : ( & ' static str , u32 , u32 ) ,
337
339
}
@@ -418,7 +420,7 @@ macro_rules! default_handler_fn {
418
420
419
421
pub ( crate ) fn default_handler<' r>(
420
422
status: Status ,
421
- req: & ' r Request <' _>
423
+ req: & ' r Request <' _>,
422
424
) -> Response <' r> {
423
425
let preferred = req. accept( ) . map( |a| a. preferred( ) ) ;
424
426
let ( mime, text) = if preferred. map_or( false , |a| a. is_json( ) ) {
0 commit comments