Improve error handling on request sending

This commit is contained in:
bitfl0wer 2023-05-14 13:07:46 +02:00
parent d5103ea03f
commit 598ad093a1
2 changed files with 11 additions and 3 deletions

View File

@ -19,6 +19,8 @@ custom_error! {
InvalidFormBodyError{error_type: String, error:String} = "The server responded with: {error_type}: {error}",
RateLimited = "Ratelimited.",
MultipartCreationError{error: String} = "Got an error whilst creating the form: {}",
TokenExpired = "Token expired, invalid or not found.",
NoPermission = "You do not have the permissions needed to perform this action.",
}
custom_error! {

View File

@ -98,9 +98,15 @@ impl LimitedRequester {
user_rate_limits,
);
if !response.status().is_success() {
Err(InstanceServerError::ReceivedErrorCodeError {
error_code: response.status().as_str().to_string(),
})
match response.status().as_u16() {
401 => return Err(InstanceServerError::TokenExpired),
403 => return Err(InstanceServerError::TokenExpired),
_ => {
return Err(InstanceServerError::ReceivedErrorCodeError {
error_code: response.status().as_str().to_string(),
})
}
}
} else {
Ok(response)
}