response_http.rs 669 B

123456789101112131415161718192021222324
  1. use crate::response::*;
  2. use actix_web::{error::ResponseError, HttpResponse};
  3. use crate::errors::ServerError;
  4. use actix_web::body::AnyBody;
  5. impl ResponseError for ServerError {
  6. fn error_response(&self) -> HttpResponse {
  7. let response: FlowyResponse = self.into();
  8. response.into()
  9. }
  10. }
  11. impl std::convert::Into<HttpResponse> for FlowyResponse {
  12. fn into(self) -> HttpResponse { HttpResponse::Ok().json(self) }
  13. }
  14. impl std::convert::Into<AnyBody> for FlowyResponse {
  15. fn into(self) -> AnyBody {
  16. match serde_json::to_string(&self) {
  17. Ok(body) => AnyBody::from(body),
  18. Err(err) => AnyBody::Empty,
  19. }
  20. }
  21. }