diff options
| author | Conrad Ludgate <conradludgate@gmail.com> | 2022-10-08 04:33:07 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-10-07 20:33:07 -0700 |
| commit | 5725f4b40b1c612d2059789cb95222ff3b0bf510 (patch) | |
| tree | 2c96c89860515efccd323b81c3be3b4e2b325ddf /atuin-server/src/handlers/mod.rs | |
| parent | Fix compatability with fish vi key bindings (#541) (diff) | |
| download | atuin-5725f4b40b1c612d2059789cb95222ff3b0bf510.zip | |
add some error messages (#510)
* add some error messages
* fmt
Diffstat (limited to 'atuin-server/src/handlers/mod.rs')
| -rw-r--r-- | atuin-server/src/handlers/mod.rs | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/atuin-server/src/handlers/mod.rs b/atuin-server/src/handlers/mod.rs index 4aa7423e..4be3e388 100644 --- a/atuin-server/src/handlers/mod.rs +++ b/atuin-server/src/handlers/mod.rs @@ -1,5 +1,4 @@ -use std::borrow::Cow; - +use atuin_common::api::ErrorResponse; use axum::{response::IntoResponse, Json}; use serde::{Deserialize, Serialize}; @@ -23,11 +22,6 @@ pub async fn index() -> Json<IndexResponse> { }) } -#[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() @@ -39,15 +33,20 @@ pub struct ErrorResponseStatus<'a> { pub status: http::StatusCode, } -impl<'a> ErrorResponse<'a> { - pub fn with_status(self, status: http::StatusCode) -> ErrorResponseStatus<'a> { +pub trait RespExt<'a> { + fn with_status(self, status: http::StatusCode) -> ErrorResponseStatus<'a>; + fn reply(reason: &'a str) -> Self; +} + +impl<'a> RespExt<'a> for ErrorResponse<'a> { + fn with_status(self, status: http::StatusCode) -> ErrorResponseStatus<'a> { ErrorResponseStatus { error: self, status, } } - pub fn reply(reason: &'a str) -> ErrorResponse { + fn reply(reason: &'a str) -> ErrorResponse { Self { reason: reason.into(), } |
