You've already forked authentication-service
mirror of
https://github.com/matrix-org/matrix-authentication-service.git
synced 2025-11-20 12:02:22 +03:00
storage: start unifying database errors
This commit is contained in:
@@ -22,7 +22,7 @@ use mas_axum_utils::http_client_factory::HttpClientFactory;
|
||||
use mas_keystore::Encrypter;
|
||||
use mas_oidc_client::requests::authorization_code::AuthorizationRequestData;
|
||||
use mas_router::UrlBuilder;
|
||||
use mas_storage::{upstream_oauth2::lookup_provider, LookupResultExt};
|
||||
use mas_storage::upstream_oauth2::lookup_provider;
|
||||
use sqlx::PgPool;
|
||||
use thiserror::Error;
|
||||
use ulid::Ulid;
|
||||
@@ -46,7 +46,7 @@ impl_from_error_for_route!(sqlx::Error);
|
||||
impl_from_error_for_route!(mas_http::ClientInitError);
|
||||
impl_from_error_for_route!(mas_oidc_client::error::DiscoveryError);
|
||||
impl_from_error_for_route!(mas_oidc_client::error::AuthorizationError);
|
||||
impl_from_error_for_route!(mas_storage::upstream_oauth2::ProviderLookupError);
|
||||
impl_from_error_for_route!(mas_storage::DatabaseError);
|
||||
|
||||
impl IntoResponse for RouteError {
|
||||
fn into_response(self) -> axum::response::Response {
|
||||
@@ -75,8 +75,7 @@ pub(crate) async fn get(
|
||||
let mut txn = pool.begin().await?;
|
||||
|
||||
let provider = lookup_provider(&mut txn, provider_id)
|
||||
.await
|
||||
.to_option()?
|
||||
.await?
|
||||
.ok_or(RouteError::ProviderNotFound)?;
|
||||
|
||||
let http_service = http_client_factory
|
||||
|
||||
@@ -96,6 +96,7 @@ pub(crate) enum RouteError {
|
||||
Anyhow(#[from] anyhow::Error),
|
||||
}
|
||||
|
||||
impl_from_error_for_route!(mas_storage::DatabaseError);
|
||||
impl_from_error_for_route!(mas_storage::GenericLookupError);
|
||||
impl_from_error_for_route!(mas_storage::upstream_oauth2::SessionLookupError);
|
||||
impl_from_error_for_route!(mas_http::ClientInitError);
|
||||
@@ -242,9 +243,7 @@ pub(crate) async fn get(
|
||||
let subject = mas_jose::claims::SUB.extract_required(&mut id_token)?;
|
||||
|
||||
// Look for an existing link
|
||||
let maybe_link = lookup_link_by_subject(&mut txn, &provider, &subject)
|
||||
.await
|
||||
.to_option()?;
|
||||
let maybe_link = lookup_link_by_subject(&mut txn, &provider, &subject).await?;
|
||||
|
||||
let link = if let Some(link) = maybe_link {
|
||||
link
|
||||
|
||||
@@ -79,6 +79,7 @@ impl_from_error_for_route!(mas_storage::user::ActiveSessionLookupError);
|
||||
impl_from_error_for_route!(mas_storage::user::UserLookupError);
|
||||
impl_from_error_for_route!(mas_axum_utils::csrf::CsrfError);
|
||||
impl_from_error_for_route!(super::cookie::UpstreamSessionNotFound);
|
||||
impl_from_error_for_route!(mas_storage::DatabaseError);
|
||||
|
||||
impl IntoResponse for RouteError {
|
||||
fn into_response(self) -> axum::response::Response {
|
||||
@@ -118,8 +119,7 @@ pub(crate) async fn get(
|
||||
.map_err(|_| RouteError::MissingCookie)?;
|
||||
|
||||
let link = lookup_link(&mut txn, link_id)
|
||||
.await
|
||||
.to_option()?
|
||||
.await?
|
||||
.ok_or(RouteError::LinkNotFound)?;
|
||||
|
||||
// This checks that we're in a browser session which is allowed to consume this
|
||||
@@ -221,8 +221,7 @@ pub(crate) async fn post(
|
||||
};
|
||||
|
||||
let link = lookup_link(&mut txn, link_id)
|
||||
.await
|
||||
.to_option()?
|
||||
.await?
|
||||
.ok_or(RouteError::LinkNotFound)?;
|
||||
|
||||
// This checks that we're in a browser session which is allowed to consume this
|
||||
|
||||
Reference in New Issue
Block a user