Merge remote-tracking branch 'origin/main' into feat/audit-log
Signed-off-by: Zomatree <me@zomatree.live>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "revolt-result"
|
||||
version = "0.12.1"
|
||||
version = "0.13.7"
|
||||
edition = "2021"
|
||||
license = "MIT"
|
||||
authors = ["Paul Makles <me@insrt.uk>"]
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
use axum::{http::StatusCode, response::IntoResponse, Json};
|
||||
use axum::{
|
||||
http::{header, StatusCode},
|
||||
response::IntoResponse,
|
||||
Json,
|
||||
};
|
||||
|
||||
use crate::{Error, ErrorType};
|
||||
|
||||
@@ -24,6 +28,7 @@ impl IntoResponse for Error {
|
||||
ErrorType::UnknownChannel => StatusCode::NOT_FOUND,
|
||||
ErrorType::UnknownMessage => StatusCode::NOT_FOUND,
|
||||
ErrorType::UnknownAttachment => StatusCode::BAD_REQUEST,
|
||||
ErrorType::CannotDeleteMessage => StatusCode::FORBIDDEN,
|
||||
ErrorType::CannotEditMessage => StatusCode::FORBIDDEN,
|
||||
ErrorType::CannotJoinCall => StatusCode::BAD_REQUEST,
|
||||
ErrorType::TooManyAttachments { .. } => StatusCode::BAD_REQUEST,
|
||||
@@ -36,9 +41,7 @@ impl IntoResponse for Error {
|
||||
ErrorType::NotInGroup => StatusCode::NOT_FOUND,
|
||||
ErrorType::AlreadyPinned => StatusCode::BAD_REQUEST,
|
||||
ErrorType::NotPinned => StatusCode::BAD_REQUEST,
|
||||
ErrorType::InSlowmode {
|
||||
retry_after: _,
|
||||
} => StatusCode::TOO_MANY_REQUESTS,
|
||||
ErrorType::InSlowmode { retry_after: _ } => StatusCode::TOO_MANY_REQUESTS,
|
||||
|
||||
ErrorType::CantCreateServers => StatusCode::FORBIDDEN,
|
||||
ErrorType::UnknownServer => StatusCode::NOT_FOUND,
|
||||
@@ -78,7 +81,7 @@ impl IntoResponse for Error {
|
||||
ErrorType::DuplicateNonce => StatusCode::CONFLICT,
|
||||
ErrorType::VosoUnavailable => StatusCode::BAD_REQUEST,
|
||||
ErrorType::NotFound => StatusCode::NOT_FOUND,
|
||||
ErrorType::NoEffect => StatusCode::OK,
|
||||
ErrorType::NoEffect => StatusCode::BAD_REQUEST,
|
||||
ErrorType::FailedValidation { .. } => StatusCode::BAD_REQUEST,
|
||||
ErrorType::LiveKitUnavailable => StatusCode::BAD_REQUEST,
|
||||
ErrorType::NotConnected => StatusCode::BAD_REQUEST,
|
||||
@@ -95,6 +98,29 @@ impl IntoResponse for Error {
|
||||
ErrorType::FileTypeNotAllowed => StatusCode::BAD_REQUEST,
|
||||
ErrorType::ImageProcessingFailed => StatusCode::INTERNAL_SERVER_ERROR,
|
||||
ErrorType::NoEmbedData => StatusCode::BAD_REQUEST,
|
||||
ErrorType::RenderFail => StatusCode::INTERNAL_SERVER_ERROR,
|
||||
ErrorType::MissingHeaders => StatusCode::BAD_REQUEST,
|
||||
ErrorType::CaptchaFailed => StatusCode::BAD_REQUEST,
|
||||
ErrorType::BlockedByShield => StatusCode::BAD_REQUEST,
|
||||
ErrorType::UnverifiedAccount => StatusCode::FORBIDDEN,
|
||||
ErrorType::EmailFailed => StatusCode::INTERNAL_SERVER_ERROR,
|
||||
ErrorType::InvalidToken => StatusCode::UNAUTHORIZED,
|
||||
ErrorType::MissingInvite => StatusCode::BAD_REQUEST,
|
||||
ErrorType::InvalidInvite => StatusCode::BAD_REQUEST,
|
||||
ErrorType::CompromisedPassword => StatusCode::BAD_REQUEST,
|
||||
ErrorType::ShortPassword => StatusCode::BAD_REQUEST,
|
||||
ErrorType::Blacklisted => {
|
||||
return (
|
||||
StatusCode::UNAUTHORIZED,
|
||||
[(header::CONTENT_TYPE, "application/json")],
|
||||
"{\"type\":\"DisallowedContactSupport\", \"note\":\"If you see this messages right here, you're probably doing something you shouldn't be.\"}"
|
||||
).into_response()
|
||||
}
|
||||
ErrorType::LockedOut => StatusCode::FORBIDDEN,
|
||||
ErrorType::TotpAlreadyEnabled => StatusCode::BAD_REQUEST,
|
||||
ErrorType::DisallowedMFAMethod => StatusCode::BAD_REQUEST,
|
||||
ErrorType::OperationFailed => StatusCode::INTERNAL_SERVER_ERROR,
|
||||
ErrorType::IncorrectData { .. } => StatusCode::BAD_REQUEST,
|
||||
};
|
||||
|
||||
(status, Json(&self)).into_response()
|
||||
|
||||
@@ -78,6 +78,7 @@ pub enum ErrorType {
|
||||
UnknownChannel,
|
||||
UnknownAttachment,
|
||||
UnknownMessage,
|
||||
CannotDeleteMessage,
|
||||
CannotEditMessage,
|
||||
CannotJoinCall,
|
||||
TooManyAttachments {
|
||||
@@ -164,6 +165,10 @@ pub enum ErrorType {
|
||||
error: String,
|
||||
},
|
||||
HeaderTooLarge,
|
||||
OperationFailed,
|
||||
IncorrectData {
|
||||
with: String,
|
||||
},
|
||||
|
||||
// ? Voice errors
|
||||
LiveKitUnavailable,
|
||||
@@ -188,6 +193,25 @@ pub enum ErrorType {
|
||||
FeatureDisabled {
|
||||
feature: String,
|
||||
},
|
||||
|
||||
// ? Authentication
|
||||
RenderFail,
|
||||
MissingHeaders,
|
||||
CaptchaFailed,
|
||||
BlockedByShield,
|
||||
UnverifiedAccount,
|
||||
EmailFailed,
|
||||
InvalidToken,
|
||||
MissingInvite,
|
||||
InvalidInvite,
|
||||
|
||||
CompromisedPassword,
|
||||
ShortPassword,
|
||||
Blacklisted,
|
||||
LockedOut,
|
||||
|
||||
TotpAlreadyEnabled,
|
||||
DisallowedMFAMethod,
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
|
||||
@@ -30,6 +30,7 @@ impl<'r> Responder<'r, 'static> for Error {
|
||||
ErrorType::UnknownChannel => Status::NotFound,
|
||||
ErrorType::UnknownMessage => Status::NotFound,
|
||||
ErrorType::UnknownAttachment => Status::BadRequest,
|
||||
ErrorType::CannotDeleteMessage => Status::Forbidden,
|
||||
ErrorType::CannotEditMessage => Status::Forbidden,
|
||||
ErrorType::CannotJoinCall => Status::BadRequest,
|
||||
ErrorType::TooManyAttachments { .. } => Status::BadRequest,
|
||||
@@ -42,9 +43,7 @@ impl<'r> Responder<'r, 'static> for Error {
|
||||
ErrorType::NotInGroup => Status::NotFound,
|
||||
ErrorType::AlreadyPinned => Status::BadRequest,
|
||||
ErrorType::NotPinned => Status::BadRequest,
|
||||
ErrorType::InSlowmode {
|
||||
retry_after: _,
|
||||
} => Status::TooManyRequests,
|
||||
ErrorType::InSlowmode { retry_after: _ } => Status::TooManyRequests,
|
||||
ErrorType::InvalidFlagValue => Status::BadRequest,
|
||||
|
||||
ErrorType::CantCreateServers => Status::Forbidden,
|
||||
@@ -84,7 +83,7 @@ impl<'r> Responder<'r, 'static> for Error {
|
||||
ErrorType::NotAuthenticated => Status::Unauthorized,
|
||||
ErrorType::DuplicateNonce => Status::Conflict,
|
||||
ErrorType::NotFound => Status::NotFound,
|
||||
ErrorType::NoEffect => Status::Ok,
|
||||
ErrorType::NoEffect => Status::BadRequest,
|
||||
ErrorType::FailedValidation { .. } => Status::BadRequest,
|
||||
ErrorType::LiveKitUnavailable => Status::BadRequest,
|
||||
ErrorType::NotAVoiceChannel => Status::BadRequest,
|
||||
@@ -101,6 +100,32 @@ impl<'r> Responder<'r, 'static> for Error {
|
||||
ErrorType::ImageProcessingFailed => Status::InternalServerError,
|
||||
ErrorType::NoEmbedData => Status::BadRequest,
|
||||
ErrorType::VosoUnavailable => Status::BadRequest,
|
||||
|
||||
ErrorType::RenderFail => Status::InternalServerError,
|
||||
ErrorType::MissingHeaders => Status::BadRequest,
|
||||
ErrorType::CaptchaFailed => Status::BadRequest,
|
||||
ErrorType::BlockedByShield => Status::BadRequest,
|
||||
ErrorType::UnverifiedAccount => Status::Forbidden,
|
||||
ErrorType::EmailFailed => Status::InternalServerError,
|
||||
ErrorType::InvalidToken => Status::Unauthorized,
|
||||
ErrorType::MissingInvite => Status::BadRequest,
|
||||
ErrorType::InvalidInvite => Status::BadRequest,
|
||||
ErrorType::CompromisedPassword => Status::BadRequest,
|
||||
ErrorType::ShortPassword => Status::BadRequest,
|
||||
ErrorType::Blacklisted => {
|
||||
// Fail blacklisted email addresses.
|
||||
const RESP: &str = "{\"type\":\"DisallowedContactSupport\", \"note\":\"If you see this messages right here, you're probably doing something you shouldn't be.\"}";
|
||||
|
||||
return Response::build()
|
||||
.status(Status::Unauthorized)
|
||||
.sized_body(RESP.len(), std::io::Cursor::new(RESP))
|
||||
.ok();
|
||||
}
|
||||
ErrorType::LockedOut => Status::Forbidden,
|
||||
ErrorType::TotpAlreadyEnabled => Status::BadRequest,
|
||||
ErrorType::DisallowedMFAMethod => Status::BadRequest,
|
||||
ErrorType::OperationFailed => Status::InternalServerError,
|
||||
ErrorType::IncorrectData { .. } => Status::BadRequest,
|
||||
};
|
||||
|
||||
// Serialize the error data structure into JSON.
|
||||
|
||||
Reference in New Issue
Block a user