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}",
|
InvalidFormBodyError{error_type: String, error:String} = "The server responded with: {error_type}: {error}",
|
||||||
RateLimited = "Ratelimited.",
|
RateLimited = "Ratelimited.",
|
||||||
MultipartCreationError{error: String} = "Got an error whilst creating the form: {}",
|
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! {
|
custom_error! {
|
||||||
|
|
12
src/limit.rs
12
src/limit.rs
|
@ -98,9 +98,15 @@ impl LimitedRequester {
|
||||||
user_rate_limits,
|
user_rate_limits,
|
||||||
);
|
);
|
||||||
if !response.status().is_success() {
|
if !response.status().is_success() {
|
||||||
Err(InstanceServerError::ReceivedErrorCodeError {
|
match response.status().as_u16() {
|
||||||
error_code: response.status().as_str().to_string(),
|
401 => return Err(InstanceServerError::TokenExpired),
|
||||||
})
|
403 => return Err(InstanceServerError::TokenExpired),
|
||||||
|
_ => {
|
||||||
|
return Err(InstanceServerError::ReceivedErrorCodeError {
|
||||||
|
error_code: response.status().as_str().to_string(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Ok(response)
|
Ok(response)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue