Improve error handling on request sending
This commit is contained in:
parent
d5103ea03f
commit
598ad093a1
|
@ -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! {
|
||||
|
|
12
src/limit.rs
12
src/limit.rs
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue