Skip to content
This repository was archived by the owner on Jan 2, 2026. It is now read-only.

Commit 6cf179f

Browse files
author
bitfl0wer
committed
fix: fix some error misformatting issues
1 parent 535b29e commit 6cf179f

File tree

6 files changed

+13
-19
lines changed

6 files changed

+13
-19
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ serde_json = "1.0.140"
3535
zeroize = { version = "1.8.1", features = ["derive"] }
3636
blake3 = "1.8.2"
3737
argon2 = "0.5.3"
38-
derive_more = { version = "2.0.1", features = ["display"] }
38+
derive_more = { version = "2.0.1", features = ["display", "from_str"] }
3939

4040
[dev-dependencies]
4141
tokio-test = "0.4"

migrations/0007_api_keys.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ CREATE TABLE IF NOT EXISTS user_tokens (
88
token_hash VARCHAR(255) PRIMARY KEY,
99
uaid UUID NOT NULL REFERENCES actors (uaid) ON DELETE CASCADE,
1010
valid_not_after TIMESTAMP NULL,
11-
cert_id BIGINT NOT NULL REFERENCES idcert (idcsr_id),
11+
cert_id BIGINT NULL REFERENCES idcert (idcsr_id),
1212
UNIQUE NULLS NOT DISTINCT (uaid, cert_id)
1313
);
1414

scripts/fresh-start.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
cargo sqlx database reset -y --source ./migrations -f && cargo run

src/api/auth/register.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub async fn register(
2323
Data(token_store): Data<&TokenStore>,
2424
) -> Result<impl IntoResponse, SonataApiError> {
2525
// TODO: Check if registration is currently allowed
26+
// TODO: Check for tos_consent
2627
// TODO: Check if registration is currently in invite-only mode
2728
if LocalActor::by_local_name(db, &payload.local_name).await?.is_some() {
2829
return Err(SonataApiError::Error(Error::new(

src/api/mod.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,25 +56,22 @@ pub(super) fn start_api(
5656
.data(db)
5757
.data(token_store);
5858

59+
let api_config_clone = api_config.clone();
5960
let handle = tokio::task::spawn(async move {
6061
Server::new(TcpListener::bind((api_config.host.as_str().trim(), api_config.port)))
6162
.run(routes)
6263
.await
6364
.expect("Failed to start HTTP server");
6465
log::info!("HTTP Server stopped");
6566
});
66-
info!("Started HTTP API server");
67+
info!("Started HTTP API server at {}, port {}", api_config_clone.host, api_config_clone.port);
6768
handle
6869
}
6970

7071
#[cfg_attr(coverage_nightly, coverage(off))]
7172
/// Catch-all fallback error.
7273
async fn custom_error(err: poem::Error) -> impl IntoResponse {
73-
Json(json! ({
74-
"success": false,
75-
"message": err.to_string(),
76-
}))
77-
.with_status(err.status())
74+
Response::builder().content_type("application/json").status(err.status()).body(err.to_string())
7875
}
7976

8077
#[cfg_attr(coverage_nightly, coverage(off))]

src/errors.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44

55
use std::fmt::Display;
66

7-
use derive_more::Display;
7+
use derive_more::{Display, FromStr};
88
use poem::{IntoResponse, Response, error::ResponseError, http::StatusCode};
99
use serde::{Deserialize, Serialize};
1010
use serde_json::json;
11+
use serde_with::{DeserializeFromStr, SerializeDisplay};
1112

1213
/// Generic error type.
1314
pub(crate) type StdError = Box<dyn std::error::Error + Sync + Send + 'static>;
@@ -64,7 +65,7 @@ impl Error {
6465
}
6566
}
6667

67-
#[derive(Debug, Clone, Copy, Display, Serialize, Deserialize, PartialEq)]
68+
#[derive(Debug, Clone, Copy, Display, PartialEq, FromStr, DeserializeFromStr, SerializeDisplay)]
6869
/// Standardized polyproto core error codes, giving a rough idea of what went
6970
/// wrong.
7071
pub enum Errcode {
@@ -82,11 +83,6 @@ pub enum Errcode {
8283
/// One or many parts of the given input did not succeed validation against
8384
/// context-specific criteria
8485
IllegalInput,
85-
#[display("P2_CORE_TOKEN_REVOKED")]
86-
/// The access token the client used has been invalidated, and will not be
87-
/// valid for any further requests. The client should try to retrieve a new
88-
/// token.
89-
TokenRevoked,
9086
}
9187

9288
impl Errcode {
@@ -104,8 +100,7 @@ impl Errcode {
104100
"Creation of the resource is not possible, as it already exists".to_owned()
105101
}
106102
Errcode::IllegalInput => "The overall input is well-formed, but one or more of the input fields fail validation criteria".to_owned(),
107-
Errcode::TokenRevoked => Errcode::TokenRevoked.to_string(),
108-
}
103+
}
109104
}
110105
}
111106

@@ -116,7 +111,6 @@ impl ResponseError for Errcode {
116111
Errcode::Unauthorized => StatusCode::UNAUTHORIZED,
117112
Errcode::Duplicate => StatusCode::CONFLICT,
118113
Errcode::IllegalInput => StatusCode::BAD_REQUEST,
119-
Errcode::TokenRevoked => StatusCode::UNAUTHORIZED,
120114
}
121115
}
122116
}
@@ -166,7 +160,7 @@ pub(crate) enum SonataApiError {
166160
/// A DB-related error.
167161
#[error(transparent)]
168162
DbError(#[from] SonataDbError),
169-
#[error("Error: {0}")]
163+
#[error("{0}")]
170164
Error(Error),
171165
}
172166

0 commit comments

Comments
 (0)