summaryrefslogtreecommitdiffstats
path: root/atuin-server/src/handlers/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'atuin-server/src/handlers/mod.rs')
-rw-r--r--atuin-server/src/handlers/mod.rs35
1 files changed, 35 insertions, 0 deletions
diff --git a/atuin-server/src/handlers/mod.rs b/atuin-server/src/handlers/mod.rs
index 83c2d0c3..9e6659e2 100644
--- a/atuin-server/src/handlers/mod.rs
+++ b/atuin-server/src/handlers/mod.rs
@@ -1,6 +1,41 @@
+use axum::{response::IntoResponse, Json};
+use serde::{Deserialize, Serialize};
+use std::borrow::Cow;
+
pub mod history;
pub mod user;
pub async fn index() -> &'static str {
"\"Through the fathomless deeps of space swims the star turtle Great A\u{2019}Tuin, bearing on its back the four giant elephants who carry on their shoulders the mass of the Discworld.\"\n\t-- Sir Terry Pratchett"
}
+
+#[derive(Debug, Serialize, Deserialize)]
+pub struct ErrorResponse<'a> {
+ pub reason: Cow<'a, str>,
+}
+
+impl<'a> IntoResponse for ErrorResponseStatus<'a> {
+ fn into_response(self) -> axum::response::Response {
+ (self.status, Json(self.error)).into_response()
+ }
+}
+
+pub struct ErrorResponseStatus<'a> {
+ pub error: ErrorResponse<'a>,
+ pub status: http::StatusCode,
+}
+
+impl<'a> ErrorResponse<'a> {
+ pub fn with_status(self, status: http::StatusCode) -> ErrorResponseStatus<'a> {
+ ErrorResponseStatus {
+ error: self,
+ status,
+ }
+ }
+
+ pub fn reply(reason: &'a str) -> ErrorResponse {
+ Self {
+ reason: reason.into(),
+ }
+ }
+}