chorus/src/errors.rs

98 lines
5.7 KiB
Rust
Raw Normal View History

2023-04-21 16:18:20 +02:00
use custom_error::custom_error;
custom_error! {
#[derive(PartialEq, Eq)]
2023-04-21 23:20:23 +02:00
pub FieldFormatError
2023-04-21 16:18:20 +02:00
PasswordError = "Password must be between 1 and 72 characters.",
UsernameError = "Username must be between 2 and 32 characters.",
ConsentError = "Consent must be 'true' to register.",
2023-04-22 11:32:44 +02:00
EmailError = "The provided email address is in an invalid format.",
2023-04-21 16:18:20 +02:00
}
2023-04-21 18:20:49 +02:00
2023-06-21 14:46:14 +02:00
pub type ChorusResult<T> = std::result::Result<T, ChorusLibError>;
2023-04-21 18:20:49 +02:00
custom_error! {
#[derive(PartialEq, Eq)]
pub ChorusLibError
2023-04-21 23:20:23 +02:00
NoResponse = "Did not receive a response from the Server.",
RequestErrorError{url:String, error:String} = "An error occured while trying to GET from {url}: {error}",
ReceivedErrorCodeError{error_code:String} = "Received the following error code while requesting from the route: {error_code}",
2023-04-22 11:32:44 +02:00
CantGetInfoError{error:String} = "Something seems to be wrong with the instance. Cannot get information about the instance: {error}",
2023-04-22 22:12:56 +02:00
InvalidFormBodyError{error_type: String, error:String} = "The server responded with: {error_type}: {error}",
2023-05-14 13:12:02 +02:00
RateLimited{bucket:String} = "Ratelimited on Bucket {bucket}",
MultipartCreationError{error: String} = "Got an error whilst creating the form: {error}",
FormCreationError{error: String} = "Got an error whilst creating the form: {error}",
TokenExpired = "Token expired, invalid or not found.",
NoPermission = "You do not have the permissions needed to perform this action.",
NotFound{error: String} = "The provided resource hasn't been found: {error}",
2023-05-16 15:58:51 +02:00
PasswordRequiredError = "You need to provide your current password to authenticate for this action.",
InvalidResponseError{error: String} = "The response is malformed and cannot be processed. Error: {error}",
InvalidArgumentsError{error: String} = "Invalid arguments were provided. Error: {error}"
2023-04-21 18:20:49 +02:00
}
2023-04-27 22:38:57 +02:00
custom_error! {
#[derive(PartialEq, Eq)]
pub ObserverError
AlreadySubscribedError = "Each event can only be subscribed to once."
}
2023-06-08 17:34:52 +02:00
custom_error! {
/// For errors we receive from the gateway, see https://discord-userdoccers.vercel.app/topics/opcodes-and-status-codes#gateway-close-event-codes;
///
/// Supposed to be sent as numbers, though they are sent as string most of the time?
///
/// Also includes errors when initiating a connection and unexpected opcodes
#[derive(Clone, PartialEq, Eq)]
2023-06-08 17:34:52 +02:00
pub GatewayError
// Errors we have received from the gateway
UnknownError = "We're not sure what went wrong. Try reconnecting?",
UnknownOpcodeError = "You sent an invalid Gateway opcode or an invalid payload for an opcode",
DecodeError = "Gateway server couldn't decode payload",
NotAuthenticatedError = "You sent a payload prior to identifying",
AuthenticationFailedError = "The account token sent with your identify payload is invalid",
AlreadyAuthenticatedError = "You've already identified, no need to reauthenticate",
InvalidSequenceNumberError = "The sequence number sent when resuming the session was invalid. Reconnect and start a new session",
RateLimitedError = "You are being rate limited!",
SessionTimedOutError = "Your session timed out. Reconnect and start a new one",
InvalidShardError = "You sent us an invalid shard when identifying",
ShardingRequiredError = "The session would have handled too many guilds - you are required to shard your connection in order to connect",
InvalidAPIVersionError = "You sent an invalid Gateway version",
InvalidIntentsError = "You sent an invalid intent",
DisallowedIntentsError = "You sent a disallowed intent. You may have tried to specify an intent that you have not enabled or are not approved for",
// Errors when initiating a gateway connection
CannotConnectError{error: String} = "Cannot connect due to a tungstenite error: {error}",
NonHelloOnInitiateError{opcode: u8} = "Received non hello on initial gateway connection ({opcode}), something is definitely wrong",
// Other misc errors
UnexpectedOpcodeReceivedError{opcode: u8} = "Received an opcode we weren't expecting to receive: {opcode}",
}
custom_error! {
// Like GatewayError for webrtc errors
// See https://discord.com/developers/docs/topics/opcodes-and-status-codes#voice;
// Also supposed to be sent by numbers, but discord is asdfghgfjkkjldf when it comes to their errors
#[derive(Clone, PartialEq, Eq)]
pub VoiceGatewayError
// Errors we receive
UnknownOpcodeError = "You sent an invalid opcode",
FailedToDecodePayloadError = "You sent an invalid payload in your identifying to the (Webrtc) Gateway",
NotAuthenticatedError = "You sent a payload before identifying with the (Webrtc) Gateway",
AuthenticationFailedError = "The token you sent in your identify payload is incorrect",
AlreadyAuthenticatedError = "You sent more than one identify payload",
SessionNoLongerValidError = "Your session is no longer valid",
SessionTimeoutError = "Your session has timed out",
ServerNotFoundError = "We can't find the server you're trying to connect to",
UnknownProtocolError = "We didn't recognize the protocol you sent",
DisconnectedError = "Channel was deleted, you were kicked, voice server changed, or the main gateway session was dropped. Should not reconnect.",
VoiceServerCrashedError = "The server crashed, try resuming",
UnknownEncryptionModeError = "Server failed to decrypt data",
// Errors when initiating a gateway connection
CannotConnectError{error: String} = "Cannot connect due to a tungstenite error: {error}",
NonHelloOnInitiateError{opcode: u8} = "Received non hello on initial gateway connection ({opcode}), something is definitely wrong",
// Other misc errors
UnexpectedOpcodeReceivedError{opcode: u8} = "Received an opcode we weren't expecting to receive: {opcode}"
}