-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror_handling.rs
More file actions
38 lines (32 loc) · 1.19 KB
/
error_handling.rs
File metadata and controls
38 lines (32 loc) · 1.19 KB
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
36
37
38
//! Example of error handling with the JSON:API library
use rjapi::{
bad_request_error, conflict_error, forbidden_error, internal_server_error, not_found_error,
};
fn main() {
// Create different types of errors
let bad_request = bad_request_error("Bad Request", "The request was malformed");
println!(
"Bad Request Error: {}",
serde_json::to_string_pretty(&bad_request.to_document::<()>()).unwrap()
);
let not_found = not_found_error("Resource not found");
println!(
"Not Found Error: {}",
serde_json::to_string_pretty(¬_found.to_document::<()>()).unwrap()
);
let forbidden = forbidden_error("Access denied");
println!(
"Forbidden Error: {}",
serde_json::to_string_pretty(&forbidden.to_document::<()>()).unwrap()
);
let conflict = conflict_error("Resource already exists");
println!(
"Conflict Error: {}",
serde_json::to_string_pretty(&conflict.to_document::<()>()).unwrap()
);
let internal_error = internal_server_error("Something went wrong");
println!(
"Internal Server Error: {}",
serde_json::to_string_pretty(&internal_error.to_document::<()>()).unwrap()
);
}