mirror of
https://github.com/Blah-IM/blahrs.git
synced 2025-07-09 15:45:33 +00:00
Add tests for room create/read and fix incorrect foreign keys
This commit is contained in:
parent
c5263c607c
commit
ff5b7e60a7
6 changed files with 224 additions and 28 deletions
|
@ -17,7 +17,7 @@ use blah::types::{
|
|||
use config::ServerConfig;
|
||||
use ed25519_dalek::SIGNATURE_LENGTH;
|
||||
use id::IdExt;
|
||||
use middleware::{ApiError, Auth, MaybeAuth, ResultExt as _, SignedJson};
|
||||
use middleware::{Auth, MaybeAuth, ResultExt as _, SignedJson};
|
||||
use parking_lot::Mutex;
|
||||
use rusqlite::{named_params, params, Connection, OptionalExtension, Row, ToSql};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
@ -33,6 +33,7 @@ mod id;
|
|||
mod utils;
|
||||
|
||||
pub use database::Database;
|
||||
pub use middleware::ApiError;
|
||||
|
||||
// Locks must be grabbed in the field order.
|
||||
#[derive(Debug)]
|
||||
|
|
|
@ -8,24 +8,28 @@ use axum::response::{IntoResponse, Response};
|
|||
use axum::{async_trait, Json};
|
||||
use blah::types::{AuthPayload, UserKey, WithSig};
|
||||
use serde::de::DeserializeOwned;
|
||||
use serde::Serialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::AppState;
|
||||
|
||||
/// Error response body for json endpoints.
|
||||
///
|
||||
/// Mostly following: <https://learn.microsoft.com/en-us/graph/errors>
|
||||
#[derive(Debug, Serialize)]
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct ApiError {
|
||||
#[serde(skip)]
|
||||
#[serde(skip, default)]
|
||||
pub status: StatusCode,
|
||||
pub code: &'static str,
|
||||
pub code: String,
|
||||
pub message: String,
|
||||
}
|
||||
|
||||
impl fmt::Display for ApiError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.write_str(&self.message)
|
||||
write!(
|
||||
f,
|
||||
"api error status={} code={}: {}",
|
||||
self.status, self.code, self.message,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -35,7 +39,7 @@ macro_rules! error_response {
|
|||
($status:expr, $code:literal, $msg:literal $(, $msg_args:expr)* $(,)?) => {
|
||||
$crate::middleware::ApiError {
|
||||
status: $status,
|
||||
code: $code,
|
||||
code: $code.to_owned(),
|
||||
message: ::std::format!($msg $(, $msg_args)*),
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue