Skip to content
Permalink
Browse files
Custom error type
  • Loading branch information
marcusbuffett committed Oct 23, 2020
1 parent 0f562ab commit 0665e484f8eb21aac1baa8ff5392fa17bf0be4d1
Showing 1 changed file with 7 additions and 2 deletions.
@@ -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>,
@@ -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>> {

0 comments on commit 0665e48

Please sign in to comment.