|
@@ -1,30 +1,30 @@
|
|
-use crate::{errors::ServerError, response::*};
|
|
|
|
|
|
+use crate::{errors::NetworkError, response::*};
|
|
use actix_web::{body::Body, error::ResponseError, HttpResponse};
|
|
use actix_web::{body::Body, error::ResponseError, HttpResponse};
|
|
use serde::Serialize;
|
|
use serde::Serialize;
|
|
|
|
|
|
-impl ResponseError for ServerError {
|
|
|
|
|
|
+impl ResponseError for NetworkError {
|
|
fn error_response(&self) -> HttpResponse {
|
|
fn error_response(&self) -> HttpResponse {
|
|
match self {
|
|
match self {
|
|
- ServerError::InternalError(msg) => {
|
|
|
|
- let resp = ServerResponse::from_msg(&msg, ServerCode::InternalError);
|
|
|
|
|
|
+ NetworkError::InternalError(msg) => {
|
|
|
|
+ let resp = FlowyResponse::from_msg(&msg, ServerCode::InternalError);
|
|
HttpResponse::InternalServerError().json(resp)
|
|
HttpResponse::InternalServerError().json(resp)
|
|
},
|
|
},
|
|
- ServerError::BadRequest(ref resp) => HttpResponse::BadRequest().json(resp),
|
|
|
|
- ServerError::Unauthorized => {
|
|
|
|
- let resp = ServerResponse::from_msg("Unauthorized", ServerCode::Unauthorized);
|
|
|
|
|
|
+ NetworkError::BadRequest(ref resp) => HttpResponse::BadRequest().json(resp),
|
|
|
|
+ NetworkError::Unauthorized => {
|
|
|
|
+ let resp = FlowyResponse::from_msg("Unauthorized", ServerCode::Unauthorized);
|
|
HttpResponse::Unauthorized().json(resp)
|
|
HttpResponse::Unauthorized().json(resp)
|
|
},
|
|
},
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-impl<T: Serialize> std::convert::Into<HttpResponse> for ServerResponse<T> {
|
|
|
|
|
|
+impl<T: Serialize> std::convert::Into<HttpResponse> for FlowyResponse<T> {
|
|
fn into(self) -> HttpResponse {
|
|
fn into(self) -> HttpResponse {
|
|
match serde_json::to_string(&self) {
|
|
match serde_json::to_string(&self) {
|
|
Ok(body) => HttpResponse::Ok().body(Body::from(body)),
|
|
Ok(body) => HttpResponse::Ok().body(Body::from(body)),
|
|
Err(e) => {
|
|
Err(e) => {
|
|
let msg = format!("Serial error: {:?}", e);
|
|
let msg = format!("Serial error: {:?}", e);
|
|
- ServerError::InternalError(msg).error_response()
|
|
|
|
|
|
+ NetworkError::InternalError(msg).error_response()
|
|
},
|
|
},
|
|
}
|
|
}
|
|
}
|
|
}
|