diff --git a/src/errors.rs b/src/errors.rs index 76d16bd..e50a931 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -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! { diff --git a/src/limit.rs b/src/limit.rs index 07dec0f..7212e7c 100644 --- a/src/limit.rs +++ b/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) }