1use std::{io::Error as IoError, sync::Arc, time::Duration};
18
19use as_variant::as_variant;
20use http::StatusCode;
21#[cfg(feature = "qrcode")]
22use matrix_sdk_base::crypto::ScanError;
23#[cfg(feature = "e2e-encryption")]
24use matrix_sdk_base::crypto::{
25 BootstrapCrossSigningError, CryptoStoreError, DecryptorError, KeyExportError, MegolmError,
26 OlmError, SignatureError,
27};
28use matrix_sdk_base::{
29 Error as SdkBaseError, QueueWedgeError, RoomState, StoreError,
30 cross_process_lock::CrossProcessLockUnobtained, event_cache::store::EventCacheStoreError,
31 media::store::MediaStoreError,
32};
33use oauth2::{RequestTokenError, basic::BasicErrorResponseType};
34use reqwest::Error as ReqwestError;
35use ruma::{
36 IdParseError,
37 api::{
38 client::uiaa::{UiaaInfo, UiaaResponse},
39 error::{
40 ErrorKind, FromHttpResponseError, IntoHttpError, RetryAfter, UnknownTokenErrorData,
41 },
42 },
43 events::{room::power_levels::PowerLevelsError, tag::InvalidUserTagName},
44 push::{InsertPushRuleError, RemovePushRuleError},
45 time::SystemTime,
46};
47use serde_json::Error as JsonError;
48use thiserror::Error;
49use url::ParseError as UrlParseError;
50
51use crate::{
52 authentication::oauth::OAuthError, cross_process_lock::CrossProcessLockError,
53 event_cache::EventCacheError, media::MediaError, room::reply::ReplyError,
54 sliding_sync::Error as SlidingSyncError,
55};
56
57pub type Result<T, E = Error> = std::result::Result<T, E>;
59
60pub type HttpResult<T> = std::result::Result<T, HttpError>;
62
63pub type RumaApiError = UiaaResponse;
66
67#[derive(Error, Debug)]
70pub enum HttpError {
71 #[error(transparent)]
73 Reqwest(#[from] ReqwestError),
74
75 #[error(transparent)]
78 Api(#[from] Box<FromHttpResponseError<RumaApiError>>),
79
80 #[error(transparent)]
83 IntoHttp(IntoHttpError),
84
85 #[error(transparent)]
87 RefreshToken(RefreshTokenError),
88
89 #[error(transparent)]
94 Cached(Arc<HttpError>),
95}
96
97#[rustfmt::skip] impl HttpError {
99 pub fn as_ruma_api_error(&self) -> Option<&RumaApiError> {
105 match self {
106 Self::Api(error) => {
107 as_variant!(error.as_ref(), FromHttpResponseError::Server)
108 },
109 _ => None
110 }
111 }
112}
113
114impl HttpError {
116 pub fn as_client_api_error(&self) -> Option<&ruma::api::error::Error> {
119 self.as_ruma_api_error().and_then(as_variant!(UiaaResponse::MatrixError))
120 }
121
122 pub fn client_api_error_kind(&self) -> Option<&ErrorKind> {
125 self.as_client_api_error().and_then(ruma::api::error::Error::error_kind)
126 }
127
128 pub(crate) fn is_rejected_token(&self) -> bool {
131 match self {
132 Self::RefreshToken(error) => error.session_rejection().is_some(),
133 Self::Cached(inner) => inner.is_rejected_token(),
134 _ => matches!(self.client_api_error_kind(), Some(ErrorKind::UnknownToken(_))),
135 }
136 }
137
138 pub fn as_uiaa_response(&self) -> Option<&UiaaInfo> {
150 self.as_ruma_api_error().and_then(as_variant!(UiaaResponse::AuthResponse))
151 }
152
153 pub(crate) fn retry_kind(&self) -> RetryKind {
156 match self {
157 HttpError::Reqwest(_) => RetryKind::NetworkFailure,
161
162 HttpError::Api(error) => match error.as_ref() {
163 FromHttpResponseError::Server(api_error) => RetryKind::from_api_error(api_error),
164 _ => RetryKind::Permanent,
165 },
166
167 HttpError::RefreshToken(error) => {
168 if error.session_rejection().is_some() {
169 RetryKind::Permanent
170 } else if let RefreshTokenError::MatrixAuth(http_error) = error {
171 http_error.retry_kind()
172 } else {
173 RetryKind::Transient { retry_after: None }
174 }
175 }
176
177 _ => RetryKind::Permanent,
178 }
179 }
180
181 pub fn is_endpoint_not_implemented(&self) -> bool {
184 self.as_client_api_error().is_some_and(|error| error.is_endpoint_not_implemented())
185 }
186}
187
188impl From<FromHttpResponseError<RumaApiError>> for HttpError {
189 fn from(value: FromHttpResponseError<RumaApiError>) -> Self {
190 Self::Api(Box::new(value))
191 }
192}
193
194const STATUS_CODE_PROXY_UNKNOWN_SERVER_ERROR: u16 = 520;
196
197#[derive(Debug)]
200pub(crate) enum RetryKind {
201 NetworkFailure,
203
204 Transient {
207 #[cfg_attr(target_family = "wasm", allow(dead_code))]
209 retry_after: Option<Duration>,
210 },
211
212 Permanent,
215}
216
217impl RetryKind {
218 fn from_api_error(api_error: &UiaaResponse) -> Self {
225 match api_error {
226 UiaaResponse::MatrixError(client_error) => match client_error.error_kind() {
227 Some(ErrorKind::LimitExceeded(limit_exceeded)) => {
228 RetryKind::from_retry_after(limit_exceeded.retry_after.as_ref())
229 }
230 Some(ErrorKind::Unrecognized) => RetryKind::Permanent,
231 _ => RetryKind::from_status_code(client_error.status_code)
232 .unwrap_or(RetryKind::Permanent),
235 },
236 UiaaResponse::AuthResponse(_) => RetryKind::Permanent,
237 }
238 }
239
240 fn from_retry_after(retry_after: Option<&RetryAfter>) -> Self {
246 let retry_after = retry_after.and_then(|retry_after| match retry_after {
247 RetryAfter::Delay(d) => Some(*d),
248 RetryAfter::DateTime(time) => time.duration_since(SystemTime::now()).ok(),
251 });
252
253 Self::Transient { retry_after }
254 }
255
256 fn from_status_code(status_code: StatusCode) -> Option<Self> {
265 match status_code {
270 StatusCode::REQUEST_TIMEOUT
273 | StatusCode::TOO_MANY_REQUESTS
274 | StatusCode::INTERNAL_SERVER_ERROR
275 | StatusCode::BAD_GATEWAY
276 | StatusCode::SERVICE_UNAVAILABLE
277 | StatusCode::GATEWAY_TIMEOUT
278 | StatusCode::INSUFFICIENT_STORAGE => Some(RetryKind::Transient { retry_after: None }),
279 _ => {
280 if status_code.as_u16() == STATUS_CODE_PROXY_UNKNOWN_SERVER_ERROR {
283 Some(RetryKind::Transient { retry_after: None })
284 } else if status_code.is_client_error() || status_code.is_server_error() {
285 Some(RetryKind::Permanent)
286 } else {
287 None
288 }
289 }
290 }
291 }
292}
293
294#[derive(Error, Debug)]
296#[non_exhaustive]
297pub enum Error {
298 #[error(transparent)]
300 Http(Box<HttpError>),
301
302 #[error("the queried endpoint requires authentication but was called before logging in")]
305 AuthenticationRequired,
306
307 #[error("Local cache doesn't contain all necessary data to perform the action.")]
309 InsufficientData,
310
311 #[cfg(feature = "e2e-encryption")]
314 #[error("The olm machine has already been initialized")]
315 BadCryptoStoreState,
316
317 #[cfg(feature = "e2e-encryption")]
319 #[error("The olm machine isn't yet available")]
320 NoOlmMachine,
321
322 #[error(transparent)]
324 SerdeJson(#[from] JsonError),
325
326 #[error(transparent)]
328 Io(#[from] IoError),
329
330 #[cfg(feature = "e2e-encryption")]
332 #[error(transparent)]
333 CryptoStoreError(Box<CryptoStoreError>),
334
335 #[error(transparent)]
337 CrossProcessLockError(Box<CrossProcessLockError>),
338
339 #[cfg(feature = "e2e-encryption")]
341 #[error(transparent)]
342 OlmError(Box<OlmError>),
343
344 #[cfg(feature = "e2e-encryption")]
346 #[error(transparent)]
347 MegolmError(Box<MegolmError>),
348
349 #[cfg(feature = "e2e-encryption")]
351 #[error(transparent)]
352 DecryptorError(#[from] DecryptorError),
353
354 #[cfg(feature = "e2e-encryption")]
356 #[error(transparent)]
357 SignatureError(#[from] SignatureError),
358
359 #[error(transparent)]
361 StateStore(Box<StoreError>),
362
363 #[error(transparent)]
365 EventCacheStore(Box<EventCacheStoreError>),
366
367 #[error(transparent)]
369 MediaStore(Box<MediaStoreError>),
370
371 #[error(transparent)]
373 Identifier(#[from] IdParseError),
374
375 #[error(transparent)]
377 Url(#[from] UrlParseError),
378
379 #[cfg(feature = "qrcode")]
381 #[error(transparent)]
382 QrCodeScanError(Box<ScanError>),
383
384 #[error(transparent)]
386 UserTagName(#[from] InvalidUserTagName),
387
388 #[error(transparent)]
390 SlidingSync(Box<SlidingSyncError>),
391
392 #[error("wrong room state: {0}")]
396 WrongRoomState(Box<WrongRoomState>),
397
398 #[error("session callbacks have been set multiple times")]
400 MultipleSessionCallbacks,
401
402 #[error(transparent)]
404 OAuth(Box<OAuthError>),
405
406 #[error("a concurrent request failed; see logs for details")]
408 ConcurrentRequestFailed,
409
410 #[cfg(not(target_family = "wasm"))]
415 #[error("unknown error: {0}")]
416 UnknownError(Box<dyn std::error::Error + Send + Sync>),
417
418 #[cfg(target_family = "wasm")]
420 #[error("unknown error: {0}")]
421 UnknownError(Box<dyn std::error::Error>),
422
423 #[error(transparent)]
425 EventCache(Box<EventCacheError>),
426
427 #[error(transparent)]
429 SendQueueWedgeError(Box<QueueWedgeError>),
430
431 #[error("backups are not enabled")]
433 BackupNotEnabled,
434
435 #[error("can't ignore the logged-in user")]
437 CantIgnoreLoggedInUser,
438
439 #[error(transparent)]
441 Media(#[from] MediaError),
442
443 #[error(transparent)]
445 ReplyError(#[from] ReplyError),
446
447 #[error("power levels error: {0}")]
449 PowerLevels(#[from] PowerLevelsError),
450
451 #[error("timed out")]
453 Timeout,
454}
455
456#[rustfmt::skip] impl Error {
458 pub fn as_ruma_api_error(&self) -> Option<&RumaApiError> {
464 as_variant!(self, Self::Http).and_then(|e| e.as_ruma_api_error())
465 }
466
467 pub fn as_client_api_error(&self) -> Option<&ruma::api::error::Error> {
470 self.as_ruma_api_error().and_then(as_variant!(UiaaResponse::MatrixError))
471 }
472
473 pub fn client_api_error_kind(&self) -> Option<&ErrorKind> {
476 self.as_client_api_error().and_then(ruma::api::error::Error::error_kind)
477 }
478
479 pub fn as_uiaa_response(&self) -> Option<&UiaaInfo> {
491 self.as_ruma_api_error().and_then(as_variant!(UiaaResponse::AuthResponse))
492 }
493}
494
495impl From<HttpError> for Error {
496 fn from(error: HttpError) -> Self {
497 Error::Http(Box::new(error))
498 }
499}
500
501#[cfg(feature = "e2e-encryption")]
502impl From<CryptoStoreError> for Error {
503 fn from(error: CryptoStoreError) -> Self {
504 Error::CryptoStoreError(Box::new(error))
505 }
506}
507
508impl From<CrossProcessLockError> for Error {
509 fn from(error: CrossProcessLockError) -> Self {
510 Error::CrossProcessLockError(Box::new(error))
511 }
512}
513
514impl From<CrossProcessLockUnobtained> for Error {
515 fn from(error: CrossProcessLockUnobtained) -> Self {
516 CrossProcessLockError::from(error).into()
517 }
518}
519
520#[cfg(feature = "e2e-encryption")]
521impl From<OlmError> for Error {
522 fn from(error: OlmError) -> Self {
523 Error::OlmError(Box::new(error))
524 }
525}
526
527#[cfg(feature = "e2e-encryption")]
528impl From<MegolmError> for Error {
529 fn from(error: MegolmError) -> Self {
530 Error::MegolmError(Box::new(error))
531 }
532}
533
534impl From<StoreError> for Error {
535 fn from(error: StoreError) -> Self {
536 Error::StateStore(Box::new(error))
537 }
538}
539
540impl From<EventCacheStoreError> for Error {
541 fn from(error: EventCacheStoreError) -> Self {
542 Error::EventCacheStore(Box::new(error))
543 }
544}
545
546impl From<MediaStoreError> for Error {
547 fn from(error: MediaStoreError) -> Self {
548 Error::MediaStore(Box::new(error))
549 }
550}
551
552#[cfg(feature = "qrcode")]
553impl From<ScanError> for Error {
554 fn from(error: ScanError) -> Self {
555 Error::QrCodeScanError(Box::new(error))
556 }
557}
558
559impl From<SlidingSyncError> for Error {
560 fn from(error: SlidingSyncError) -> Self {
561 Error::SlidingSync(Box::new(error))
562 }
563}
564
565impl From<OAuthError> for Error {
566 fn from(error: OAuthError) -> Self {
567 Error::OAuth(Box::new(error))
568 }
569}
570
571impl From<EventCacheError> for Error {
572 fn from(error: EventCacheError) -> Self {
573 Error::EventCache(Box::new(error))
574 }
575}
576
577impl From<QueueWedgeError> for Error {
578 fn from(error: QueueWedgeError) -> Self {
579 Error::SendQueueWedgeError(Box::new(error))
580 }
581}
582
583#[cfg(feature = "e2e-encryption")]
584impl From<BootstrapCrossSigningError> for Error {
585 fn from(error: BootstrapCrossSigningError) -> Self {
586 match error {
587 BootstrapCrossSigningError::CryptoStore(e) => e.into(),
588 BootstrapCrossSigningError::Signature(e) => e.into(),
589 }
590 }
591}
592
593#[cfg(feature = "e2e-encryption")]
595#[derive(Error, Debug)]
596#[allow(dead_code)]
598#[cfg_attr(feature = "uniffi", derive(uniffi::Error), uniffi(flat_error))]
601pub enum RoomKeyImportError {
602 #[error(transparent)]
604 SerdeJson(#[from] JsonError),
605
606 #[error("The crypto store hasn't been yet opened, can't import yet.")]
609 StoreClosed,
610
611 #[error(transparent)]
613 Io(#[from] IoError),
614
615 #[error(transparent)]
617 CryptoStore(#[from] CryptoStoreError),
618
619 #[error(transparent)]
621 Export(#[from] KeyExportError),
622}
623
624impl From<FromHttpResponseError<ruma::api::error::Error>> for HttpError {
625 fn from(err: FromHttpResponseError<ruma::api::error::Error>) -> Self {
626 Self::Api(Box::new(err.map(Into::into)))
627 }
628}
629
630impl From<SdkBaseError> for Error {
631 fn from(e: SdkBaseError) -> Self {
632 match e {
633 SdkBaseError::StateStore(e) => Self::StateStore(Box::new(e)),
634 #[cfg(feature = "e2e-encryption")]
635 SdkBaseError::CryptoStore(e) => Self::CryptoStoreError(Box::new(e)),
636 #[cfg(feature = "e2e-encryption")]
637 SdkBaseError::BadCryptoStoreState => Self::BadCryptoStoreState,
638 #[cfg(feature = "e2e-encryption")]
639 SdkBaseError::OlmError(e) => Self::OlmError(Box::new(e)),
640 #[cfg(feature = "eyre")]
641 _ => Self::UnknownError(eyre::eyre!(e).into()),
642 #[cfg(all(not(feature = "eyre"), feature = "anyhow", not(target_family = "wasm")))]
643 _ => Self::UnknownError(anyhow::anyhow!(e).into()),
644 #[cfg(all(not(feature = "eyre"), feature = "anyhow", target_family = "wasm"))]
645 _ => Self::UnknownError(e.into()),
646 #[cfg(all(
647 not(feature = "eyre"),
648 not(feature = "anyhow"),
649 not(target_family = "wasm")
650 ))]
651 _ => {
652 let e: Box<dyn std::error::Error + Send + Sync> = format!("{e:?}").into();
653 Self::UnknownError(e)
654 }
655 #[cfg(all(not(feature = "eyre"), not(feature = "anyhow"), target_family = "wasm"))]
656 _ => {
657 let e: Box<dyn std::error::Error> = format!("{e:?}").into();
658 Self::UnknownError(e)
659 }
660 }
661 }
662}
663
664impl From<ReqwestError> for Error {
665 fn from(e: ReqwestError) -> Self {
666 Error::Http(Box::new(HttpError::Reqwest(e)))
667 }
668}
669
670#[derive(Debug, Error)]
672pub enum BeaconError {
673 #[error("Network error: {0}")]
675 Network(#[from] HttpError),
676
677 #[error("Existing beacon information not found.")]
679 NotFound,
680
681 #[error("Beacon event is redacted and cannot be processed.")]
683 Redacted,
684
685 #[error("Must join the room to access beacon information.")]
687 Stripped,
688
689 #[error("Deserialization error: {0}")]
691 Deserialization(#[from] serde_json::Error),
692
693 #[error("The beacon event has expired.")]
695 NotLive,
696
697 #[error("Other error: {0}")]
699 Other(Box<Error>),
700}
701
702impl From<Error> for BeaconError {
703 fn from(err: Error) -> Self {
704 BeaconError::Other(Box::new(err))
705 }
706}
707
708#[derive(Debug, Error, Clone)]
716pub enum RefreshTokenError {
717 #[error("missing refresh token")]
719 RefreshTokenRequired,
720
721 #[error(transparent)]
723 MatrixAuth(Arc<HttpError>),
724
725 #[error(transparent)]
727 OAuth(#[from] Arc<OAuthError>),
728}
729
730impl RefreshTokenError {
731 pub(crate) fn session_rejection(&self) -> Option<UnknownTokenErrorData> {
734 match self {
735 Self::RefreshTokenRequired => Some(UnknownTokenErrorData::default()),
737
738 Self::MatrixAuth(error) => {
739 if error.as_client_api_error()?.status_code != StatusCode::UNAUTHORIZED {
740 return None;
741 }
742 match error.client_api_error_kind()? {
743 ErrorKind::UnknownToken(data) => Some(data.clone()),
744 _ => None,
745 }
746 }
747
748 Self::OAuth(oauth_error) => matches!(
749 &**oauth_error,
750 OAuthError::RefreshToken(RequestTokenError::ServerResponse(error_response))
751 if *error_response.error() == BasicErrorResponseType::InvalidGrant
752 )
753 .then(UnknownTokenErrorData::default),
754 }
755 }
756}
757
758#[derive(Debug, Error, Clone, PartialEq)]
760pub enum NotificationSettingsError {
761 #[error("Invalid parameter `{0}`")]
763 InvalidParameter(String),
764 #[error("Unable to add push rule")]
766 UnableToAddPushRule,
767 #[error("Unable to remove push rule")]
769 UnableToRemovePushRule,
770 #[error("Unable to update push rule")]
772 UnableToUpdatePushRule,
773 #[error("Rule `{0}` not found")]
775 RuleNotFound(String),
776 #[error("Unable to save push rules")]
778 UnableToSavePushRules,
779}
780
781impl NotificationSettingsError {
782 pub fn is_rule_not_found(&self) -> bool {
784 matches!(self, Self::RuleNotFound(_))
785 }
786}
787
788impl From<InsertPushRuleError> for NotificationSettingsError {
789 fn from(_: InsertPushRuleError) -> Self {
790 Self::UnableToAddPushRule
791 }
792}
793
794impl From<RemovePushRuleError> for NotificationSettingsError {
795 fn from(_: RemovePushRuleError) -> Self {
796 Self::UnableToRemovePushRule
797 }
798}
799
800#[derive(Debug, Error)]
801#[error("expected: {expected}, got: {got:?}")]
802pub struct WrongRoomState {
803 expected: &'static str,
804 got: RoomState,
805}
806
807impl WrongRoomState {
808 pub(crate) fn new(expected: &'static str, got: RoomState) -> Self {
809 Self { expected, got }
810 }
811}
812
813#[cfg(test)]
814mod tests {
815 use std::time::Duration;
816
817 use assert_matches::assert_matches;
818 use http::StatusCode;
819 use ruma::{
820 api::{EndpointError as _, error::RetryAfter},
821 time::SystemTime,
822 };
823
824 use super::{
825 HttpError, RefreshTokenError, RetryKind, RumaApiError,
826 STATUS_CODE_PROXY_UNKNOWN_SERVER_ERROR,
827 };
828 use crate::error::FromHttpResponseError;
829
830 fn refresh_failure(status_code: StatusCode, body: &str) -> HttpError {
833 let response = http::Response::builder().status(status_code).body(body.as_bytes()).unwrap();
834 let api_error = RumaApiError::from_http_response(response);
835
836 HttpError::RefreshToken(RefreshTokenError::MatrixAuth(std::sync::Arc::new(HttpError::Api(
837 Box::new(FromHttpResponseError::Server(api_error)),
838 ))))
839 }
840
841 #[test]
842 fn test_retry_kind_of_a_failed_refresh() {
843 assert_matches!(
845 refresh_failure(StatusCode::BAD_GATEWAY, "").retry_kind(),
846 RetryKind::Transient { .. }
847 );
848
849 assert_matches!(
852 refresh_failure(
853 StatusCode::UNAUTHORIZED,
854 r#"{"errcode": "M_UNKNOWN_TOKEN", "error": "Token is not active"}"#,
855 )
856 .retry_kind(),
857 RetryKind::Permanent
858 );
859
860 assert_matches!(
862 HttpError::RefreshToken(RefreshTokenError::RefreshTokenRequired).retry_kind(),
863 RetryKind::Permanent
864 );
865
866 assert_matches!(
867 refresh_failure(
868 StatusCode::NOT_FOUND,
869 r#"{"errcode": "M_UNRECOGNIZED", "error": "Not found"}"#
870 )
871 .retry_kind(),
872 RetryKind::Permanent
873 );
874
875 assert_matches!(
876 refresh_failure(
877 StatusCode::TOO_MANY_REQUESTS,
878 r#"{"errcode": "M_LIMIT_EXCEEDED", "error": "Too many requests", "retry_after_ms": 2000}"#,
879 )
880 .retry_kind(),
881 RetryKind::Transient { retry_after: Some(delay) } => {
882 assert_eq!(delay, Duration::from_secs(2));
883 }
884 );
885 }
886
887 #[test]
888 fn test_retry_kind_from_retry_after() {
889 assert_matches!(
890 RetryKind::from_retry_after(None),
891 RetryKind::Transient { retry_after: None }
892 );
893
894 assert_matches!(
895 RetryKind::from_retry_after(Some(&RetryAfter::Delay(Duration::from_secs(5)))),
896 RetryKind::Transient { retry_after: Some(delay) } => {
897 assert_eq!(delay, Duration::from_secs(5));
898 }
899 );
900
901 let in_a_minute = SystemTime::now() + Duration::from_secs(60);
903 assert_matches!(
904 RetryKind::from_retry_after(Some(&RetryAfter::DateTime(in_a_minute))),
905 RetryKind::Transient { retry_after: Some(delay) } => {
906 assert!(delay > Duration::from_secs(55));
907 assert!(delay <= Duration::from_secs(60));
908 }
909 );
910
911 let a_minute_ago = SystemTime::now() - Duration::from_secs(60);
913 assert_matches!(
914 RetryKind::from_retry_after(Some(&RetryAfter::DateTime(a_minute_ago))),
915 RetryKind::Transient { retry_after: None }
916 );
917 }
918
919 #[test]
920 fn test_retry_kind_of_http_status_codes() {
921 let retry_status_code = [
922 StatusCode::REQUEST_TIMEOUT,
923 StatusCode::TOO_MANY_REQUESTS,
924 StatusCode::INTERNAL_SERVER_ERROR,
925 StatusCode::BAD_GATEWAY,
926 StatusCode::SERVICE_UNAVAILABLE,
927 StatusCode::GATEWAY_TIMEOUT,
928 StatusCode::INSUFFICIENT_STORAGE,
929 StatusCode::from_u16(STATUS_CODE_PROXY_UNKNOWN_SERVER_ERROR).unwrap(),
930 ];
931
932 for code in retry_status_code.iter() {
934 assert_matches!(
935 RetryKind::from_status_code(code.to_owned()),
936 Some(RetryKind::Transient { .. })
937 );
938 }
939
940 for i in 1..400 {
942 let Ok(code) = StatusCode::from_u16(i) else {
943 continue;
944 };
945 if retry_status_code.contains(&code) {
946 continue;
947 }
948 assert_matches!(RetryKind::from_status_code(code.to_owned()), None);
949 }
950
951 for i in 400..600 {
953 let Ok(code) = StatusCode::from_u16(i) else {
954 continue;
955 };
956 if retry_status_code.contains(&code) {
957 continue;
958 }
959 assert_matches!(RetryKind::from_status_code(code), Some(RetryKind::Permanent));
960 }
961 }
962}