Fix 500 when pushing to non-existent org
Closes #26
Diff
chartered-db/src/crates.rs | 4 ++++
chartered-web/src/endpoints/cargo_api/publish.rs | 7 ++++++-
2 files changed, 7 insertions(+), 4 deletions(-)
@@ -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) {
@@ -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,
}
}