-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy patherror.mbt
More file actions
35 lines (29 loc) · 967 Bytes
/
Copy patherror.mbt
File metadata and controls
35 lines (29 loc) · 967 Bytes
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
///|
pub suberror IOError
///|
pub suberror NetworkError
///|
pub suberror ExecError
///|
// 请求错误处理器:接收事件和未捕获的错误,返回一个响应。
// 用于记录日志、返回自定义错误响应等。
pub type ErrorHandler = (MocketEvent, Error) -> &Responder
///|
// 默认错误处理器:返回 500 Internal Server Error 并附带错误信息。
fn default_error_handler(_event : MocketEvent, err : Error) -> &Responder {
HttpResponse::new(InternalServerError).body(err.to_string())
}
///|
// 将未捕获的请求错误转换为响应,优先使用用户注册的错误处理器。
fn Mocket::handle_request_error(
self : Mocket,
event : MocketEvent,
err : Error,
) -> &Responder {
(self.error_handler)(event, err)
}
///|
// 注册请求错误处理器,用于记录日志或返回自定义错误响应。
pub fn Mocket::on_error(self : Mocket, handler : ErrorHandler) -> Unit {
self.error_handler = handler
}