feat: Chat request implementation #14
2 changed files with 13 additions and 2 deletions
|
@ -53,6 +53,7 @@ impl From<DbErr> for ServerError {
|
|||
impl From<ServerError> for WsError {
|
||||
fn from(err: ServerError) -> Self {
|
||||
match err {
|
||||
ServerError::Api(ApiError::NotRegisteredUser) => WsError::RegistredUserEvent,
|
||||
ServerError::Internal(_) | ServerError::Api(_) => WsError::InternalServerError,
|
||||
ServerError::Ws(err) => err,
|
||||
}
|
||||
|
@ -62,6 +63,7 @@ impl From<ServerError> for WsError {
|
|||
impl From<ServerError> for ApiError {
|
||||
fn from(err: ServerError) -> Self {
|
||||
match err {
|
||||
ServerError::Ws(WsError::RegistredUserEvent) => ApiError::NotRegisteredUser,
|
||||
ServerError::Internal(_) | ServerError::Ws(_) => ApiError::Internal,
|
||||
ServerError::Api(err) => err,
|
||||
}
|
||||
|
|
|
@ -41,6 +41,13 @@ pub enum ApiError {
|
|||
/// (400 Bad Request)
|
||||
#[error("You entered two different public keys")]
|
||||
TwoDifferentKeys,
|
||||
/// Error in the query parameters (400 Bad Request)
|
||||
#[error("{0}")]
|
||||
Querys(String),
|
||||
/// Non registered user tried to access to registered user only endpoint
|
||||
/// (403 Forbidden)
|
||||
#[error("You are not a registered user, please register first")]
|
||||
NotRegisteredUser,
|
||||
}
|
||||
|
||||
impl ApiError {
|
||||
|
@ -48,8 +55,10 @@ impl ApiError {
|
|||
pub const fn status_code(&self) -> StatusCode {
|
||||
match self {
|
||||
Self::Internal => StatusCode::INTERNAL_SERVER_ERROR,
|
||||
Self::RegistrationClosed => StatusCode::FORBIDDEN,
|
||||
Self::AlreadyRegistered | Self::TwoDifferentKeys => StatusCode::BAD_REQUEST,
|
||||
Self::RegistrationClosed | Self::NotRegisteredUser => StatusCode::FORBIDDEN,
|
||||
Self::AlreadyRegistered | Self::TwoDifferentKeys | Self::Querys(_) => {
|
||||
StatusCode::BAD_REQUEST
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue