main
Elnu 2 years ago
parent 1de25aaca9
commit 1253539efa

@ -53,7 +53,9 @@ impl CommentCreationError {
fn to_http_response(&self) -> HttpResponse { fn to_http_response(&self) -> HttpResponse {
match self { match self {
Self::DatabaseAccessError(error) => error.to_http_response(), Self::DatabaseAccessError(error) => error.to_http_response(),
Self::BadParent => HttpResponse::BadRequest().reason("invalid comment parent").finish(), Self::BadParent => HttpResponse::BadRequest()
.reason("invalid comment parent")
.finish(),
} }
} }
} }
@ -255,16 +257,24 @@ async fn post_comment(
} }
} }
} }
Err(_) => return Err(CommentCreationError::DatabaseAccessError(DatabaseAccessError::DatabaseError)), Err(_) => {
return Err(CommentCreationError::DatabaseAccessError(
DatabaseAccessError::DatabaseError,
))
}
}; };
return Err(CommentCreationError::BadParent); return Err(CommentCreationError::BadParent);
} }
} }
if let Err(_) = database.create_comment(&comment) { if let Err(_) = database.create_comment(&comment) {
return Err(CommentCreationError::DatabaseAccessError(DatabaseAccessError::DatabaseError)); return Err(CommentCreationError::DatabaseAccessError(
DatabaseAccessError::DatabaseError,
));
} }
Ok(()) Ok(())
}).await { })
.await
{
Ok(result) => match result { Ok(result) => match result {
Ok(_) => HttpResponse::Ok().into(), Ok(_) => HttpResponse::Ok().into(),
Err(error) => error.to_http_response(), Err(error) => error.to_http_response(),

Loading…
Cancel
Save