mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-06-14 11:29:22 +00:00
d075acce43
- Diesel ordinarily throws an error when no results are returned for a single fetch, which is a bit confusing. This PR ensures that the missing value cases are all caught, and wrapped with new LemmyErrors, rather than diesel errors. - Fixes #4601
24 lines
725 B
Rust
24 lines
725 B
Rust
use actix_web::web::{Data, Json};
|
|
use lemmy_api_common::{
|
|
context::LemmyContext,
|
|
site::GetFederatedInstancesResponse,
|
|
utils::build_federated_instances,
|
|
};
|
|
use lemmy_db_views::structs::SiteView;
|
|
use lemmy_utils::{error::LemmyResult, LemmyErrorType};
|
|
|
|
#[tracing::instrument(skip(context))]
|
|
pub async fn get_federated_instances(
|
|
context: Data<LemmyContext>,
|
|
) -> LemmyResult<Json<GetFederatedInstancesResponse>> {
|
|
let site_view = SiteView::read_local(&mut context.pool())
|
|
.await?
|
|
.ok_or(LemmyErrorType::LocalSiteNotSetup)?;
|
|
let federated_instances =
|
|
build_federated_instances(&site_view.local_site, &mut context.pool()).await?;
|
|
|
|
Ok(Json(GetFederatedInstancesResponse {
|
|
federated_instances,
|
|
}))
|
|
}
|