diff --git a/rfd-api/src/endpoints/rfd.rs b/rfd-api/src/endpoints/rfd.rs index d744c123..7f034549 100644 --- a/rfd-api/src/endpoints/rfd.rs +++ b/rfd-api/src/endpoints/rfd.rs @@ -31,7 +31,7 @@ use crate::{ endpoints::UNLIMITED, permissions::RfdPermission, search::{MeiliSearchResult, SearchRequest}, - util::response::{client_error, internal_error, unauthorized}, + util::response::{client_error, internal_error, not_implemented, unauthorized}, }; #[derive(Debug, Deserialize, JsonSchema)] @@ -180,7 +180,10 @@ pub async fn view_rfd_discussion( rqctx: RequestContext, path: Path, ) -> Result, HttpError> { - unimplemented!() + let ctx = rqctx.context(); + let caller = ctx.v_ctx().get_caller(&rqctx).await?; + let path = path.into_inner(); + view_rfd_discussion_op(ctx, &caller, path.number, None).await } // Specific RFD revision endpoints @@ -295,7 +298,10 @@ pub async fn view_rfd_revision_discussion( rqctx: RequestContext, path: Path, ) -> Result, HttpError> { - unimplemented!() + let ctx = rqctx.context(); + let caller = ctx.v_ctx().get_caller(&rqctx).await?; + let path = path.into_inner(); + view_rfd_discussion_op(ctx, &caller, path.number, Some(path.revision.into())).await } #[derive(Debug, Deserialize, JsonSchema)] @@ -486,15 +492,18 @@ async fn view_rfd_attr_op( } } -#[allow(dead_code)] #[instrument(skip(_ctx, caller), fields(caller = ?caller.id), err(Debug))] async fn view_rfd_discussion_op( _ctx: &RfdContext, caller: &Caller, - number: String, - revision: Option, -) -> Result, HttpError> { - unimplemented!() + _number: String, + _revision: Option, +) -> Result, HttpError> { + // Discussion retrieval is not implemented. Respond with a well formed error rather than + // panicking, which drops the connection and leaves clients with an empty response body. + Err(not_implemented( + "RFD discussion retrieval is not implemented", + )) } #[instrument(skip(ctx, caller), fields(caller = ?caller.id), err(Debug))] diff --git a/rfd-api/src/util.rs b/rfd-api/src/util.rs index 6c0b6964..cb061314 100644 --- a/rfd-api/src/util.rs +++ b/rfd-api/src/util.rs @@ -3,7 +3,7 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. pub mod response { - use dropshot::{ClientErrorStatusCode, HttpError}; + use dropshot::{ClientErrorStatusCode, ErrorStatusCode, HttpError}; use std::error::Error; use tracing::instrument; @@ -36,4 +36,18 @@ pub mod response { tracing::error!(internal_message, "Request failed"); HttpError::for_internal_error(internal_message) } + + pub fn not_implemented(message: S) -> HttpError + where + S: ToString, + { + let message = message.to_string(); + HttpError { + status_code: ErrorStatusCode::NOT_IMPLEMENTED, + error_code: None, + external_message: message.clone(), + internal_message: message, + headers: None, + } + } }