Skip to content

Commit 541f710

Browse files
committed
Add module level documentation describing typical usage of error types
1 parent 8800959 commit 541f710

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/util/errors.rs

+14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
//! This module implements several error types and traits. The suggested usage in returned results
2+
//! is as follows:
3+
//!
4+
//! * The concrete `util::concrete::Error` type (re-exported as `util::Error`) is great for code
5+
//! that is not part of the request/response lifecycle. It avoids pulling in the unnecessary
6+
//! infrastructure to convert errors into a user facing JSON responses (relative to `AppError`).
7+
//! * `diesel::QueryResult` - There is a lot of code that only deals with query errors. If only
8+
//! one type of error is possible in a function, using that specific error is preferable to the
9+
//! more general `util::Error`. This is especially common in model code.
10+
//! * `util::errors::AppResult` - Some failures should be converted into user facing JSON
11+
//! responses. This error type is more dynamic and is box allocated. Low-level errors are
12+
//! typically not converted to user facing errors and most usage is within the models,
13+
//! controllers, and middleware layers.
14+
115
use std::any::{Any, TypeId};
216
use std::error::Error;
317
use std::fmt;

0 commit comments

Comments
 (0)