response_http.rs 679 B

1234567891011121314151617181920212223242526
  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 {
  13. HttpResponse::Ok().json(self)
  14. }
  15. }
  16. impl std::convert::Into<AnyBody> for FlowyResponse {
  17. fn into(self) -> AnyBody {
  18. match serde_json::to_string(&self) {
  19. Ok(body) => AnyBody::from(body),
  20. Err(_) => AnyBody::Empty,
  21. }
  22. }
  23. }