1
0
mirror of https://github.com/matrix-org/matrix-authentication-service.git synced 2025-07-29 22:01:14 +03:00

storage: start unifying database errors

This commit is contained in:
Quentin Gliech
2022-12-07 16:04:46 +01:00
parent 12ce2a3d04
commit 1ddc05ff01
13 changed files with 143 additions and 62 deletions

View File

@ -6,6 +6,7 @@ edition = "2021"
license = "Apache-2.0"
[dependencies]
anyhow = "1.0.66"
async-graphql = { version = "5.0.2", features = ["chrono", "url"] }
chrono = "0.4.23"
serde = { version = "1.0.149", features = ["derive"] }

View File

@ -188,9 +188,7 @@ impl RootQuery {
let Some(session) = session else { return Ok(None) };
let current_user = session.user;
let link = mas_storage::upstream_oauth2::lookup_link(&mut conn, id)
.await
.to_option()?;
let link = mas_storage::upstream_oauth2::lookup_link(&mut conn, id).await?;
// Ensure that the link belongs to the current user
let link = link.filter(|link| link.user_id == Some(current_user.id));
@ -208,9 +206,7 @@ impl RootQuery {
let database = ctx.data::<PgPool>()?;
let mut conn = database.acquire().await?;
let provider = mas_storage::upstream_oauth2::lookup_provider(&mut conn, id)
.await
.to_option()?;
let provider = mas_storage::upstream_oauth2::lookup_provider(&mut conn, id).await?;
Ok(provider.map(UpstreamOAuth2Provider::new))
}

View File

@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use anyhow::Context as _;
use async_graphql::{Context, Object, ID};
use chrono::{DateTime, Utc};
use sqlx::PgPool;
@ -100,7 +101,9 @@ impl UpstreamOAuth2Link {
// Fetch on-the-fly
let database = ctx.data::<PgPool>()?;
let mut conn = database.acquire().await?;
mas_storage::upstream_oauth2::lookup_provider(&mut conn, self.link.provider_id).await?
mas_storage::upstream_oauth2::lookup_provider(&mut conn, self.link.provider_id)
.await?
.context("Upstream OAuth 2.0 provider not found")?
};
Ok(UpstreamOAuth2Provider::new(provider))