Skip to content

Commit d123dc9

Browse files
committed
refactor(sdk): Use upstream method to match unsupported endpoint error
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
1 parent c253114 commit d123dc9

2 files changed

Lines changed: 9 additions & 9 deletions

File tree

crates/matrix-sdk/src/authentication/oauth/mod.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ use self::{
225225
};
226226
use super::{AuthData, SessionTokens};
227227
use crate::{
228-
Client, HttpError, RefreshTokenError, Result,
228+
Client, RefreshTokenError, Result,
229229
client::{SessionChange, caches::CachedValue},
230230
executor::spawn,
231231
utils::UrlOrQuery,
@@ -521,17 +521,11 @@ impl OAuth {
521521
async fn server_metadata_inner(
522522
&self,
523523
) -> Result<AuthorizationServerMetadata, OAuthDiscoveryError> {
524-
let is_endpoint_unsupported = |error: &HttpError| {
525-
error
526-
.as_client_api_error()
527-
.is_some_and(|err| err.status_code == http::StatusCode::NOT_FOUND)
528-
};
529-
530524
let response =
531525
self.client.send(get_authorization_server_metadata::v1::Request::new()).await.map_err(
532526
|error| {
533-
// If the endpoint returns a 404, i.e. the server doesn't support the endpoint.
534-
if is_endpoint_unsupported(&error) {
527+
// If the server doesn't support the endpoint.
528+
if error.is_endpoint_not_implemented() {
535529
OAuthDiscoveryError::NotSupported
536530
} else {
537531
error.into()

crates/matrix-sdk/src/error.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,12 @@ impl HttpError {
180180
_ => RetryKind::Permanent,
181181
}
182182
}
183+
184+
/// If this is a server error, returns whether it matches the expected
185+
/// format for an endpoint that is not implemented.
186+
pub fn is_endpoint_not_implemented(&self) -> bool {
187+
self.as_client_api_error().is_some_and(|error| error.is_endpoint_not_implemented())
188+
}
183189
}
184190

185191
impl From<FromHttpResponseError<RumaApiError>> for HttpError {

0 commit comments

Comments
 (0)