Skip to content

Commit

Permalink
Custom error type
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusbuffett committed Oct 23, 2020
1 parent 0f562ab commit 0665e48
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ use rocket_contrib::json::Json;
use serde::{Deserialize, Serialize};
use sled_extensions::bincode::Tree;
use sled_extensions::DbExt;
use std::error::Error;

#[derive(thiserror::Error, Debug)]
pub enum ServerError {
#[error("sled db error")]
SledError(#[from] sled_extensions::Error),
}

struct Database {
users: Tree<User>,
Expand All @@ -20,7 +25,7 @@ struct User {
favorite_food: String,
}

type EndpointResult<T> = Result<T, &'static str>;
type EndpointResult<T> = Result<T, ServerError>;

#[get("/users/<username>")]
fn get_user(db: State<Database>, username: String) -> EndpointResult<Json<User>> {
Expand Down

0 comments on commit 0665e48

Please sign in to comment.