From b404344a7c4ab5cb6c7d7b445fab796be79b848f Mon Sep 17 00:00:00 2001 From: Owen Jacobson Date: Tue, 3 Sep 2024 01:25:20 -0400 Subject: Allow login creation and authentication. This is a beefy change, as it adds a TON of smaller pieces needed to make this all function: * A database migration. * A ton of new crates for things like password validation, timekeeping, and HTML generation. * A first cut at a module structure for routes, templates, repositories. * A family of ID types, for identifying various kinds of domain thing. * AppError, which _doesn't_ implement Error but can be sent to clients. --- src/error.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/error.rs (limited to 'src/error.rs') diff --git a/src/error.rs b/src/error.rs new file mode 100644 index 0000000..2d512e6 --- /dev/null +++ b/src/error.rs @@ -0,0 +1,37 @@ +use std::error; + +use axum::{ + http::StatusCode, + response::{IntoResponse, Response}, +}; + +// I'm making an effort to avoid `anyhow` here, as that crate is _enormously_ +// complex (though very usable). We don't need to be overly careful about +// allocations on errors in this app, so this is fine for most "general +// failure" cases. +// +// If that changes, my hope is to use `thiserror` or something with a similar +// strategy, before resorting to `anyhow`. +pub type BoxedError = Box; + +// Returns a 500 Internal Server Error to the client. Meant to be used via the +// `?` operator; _does not_ return the originating error to the client. +#[derive(Debug)] +pub struct InternalError; + +impl From for InternalError +where + E: Into, +{ + fn from(_: E) -> InternalError { + // At some point it may be useful for this to record the originating + // error so that it can be logged… -oj + InternalError + } +} + +impl IntoResponse for InternalError { + fn into_response(self) -> Response { + (StatusCode::INTERNAL_SERVER_ERROR, "internal server error").into_response() + } +} -- cgit v1.2.3