From d35012210d260b473f7eacd034e491013deb34d4 Mon Sep 17 00:00:00 2001 From: Jordan Doyle Date: Thu, 04 Nov 2021 23:01:24 +0000 Subject: [PATCH] Fix 500 when pushing to non-existent org Closes #26 --- chartered-db/src/crates.rs | 4 ++++ chartered-web/src/endpoints/cargo_api/publish.rs | 7 ++++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/chartered-db/src/crates.rs b/chartered-db/src/crates.rs index f1db911..16f894c 100644 --- a/chartered-db/src/crates.rs +++ a/chartered-db/src/crates.rs @@ -301,7 +301,9 @@ .on(organisation_id.eq(id).and(user_id.eq(requesting_user_id))), ) .select((id, permissions)) - .first::<(i32, UserPermission)>(&conn)?; + .first::<(i32, UserPermission)>(&conn) + .optional()? + .ok_or(Error::MissingOrganisation)?; #[allow(clippy::if_not_else)] if !perms.contains(UserPermission::VISIBLE) { diff --git a/chartered-web/src/endpoints/cargo_api/publish.rs b/chartered-web/src/endpoints/cargo_api/publish.rs index 685c9ad..c256325 100644 --- a/chartered-web/src/endpoints/cargo_api/publish.rs +++ a/chartered-web/src/endpoints/cargo_api/publish.rs @@ -245,10 +245,11 @@ use axum::http::StatusCode; match self { + Self::JsonParse(_) + | Self::MetadataParse + | Self::InvalidCrateName + | Self::Database(chartered_db::Error::MissingOrganisation) => StatusCode::BAD_REQUEST, Self::Database(e) => e.status_code(), - Self::JsonParse(_) | Self::MetadataParse | Self::InvalidCrateName => { - StatusCode::BAD_REQUEST - } Self::File(_) => StatusCode::INTERNAL_SERVER_ERROR, } } -- rgit 0.1.3