api: just return error on db failure
let's do conflict properly
This commit is contained in:
parent
7046e51d01
commit
ecf3998b5a
15
src/api.rs
15
src/api.rs
|
@ -173,22 +173,13 @@ fn items_sync(db: DbConn, u: user::User, params: Json<SyncParams>) -> Custom<Jso
|
|||
|
||||
// First, update all items sent by client
|
||||
for mut it in inner_params.items.into_iter() {
|
||||
let old_updated_at = it.updated_at.clone();
|
||||
// Always update updated_at for all items on server
|
||||
it.updated_at =
|
||||
Some(chrono::Utc::now().to_rfc3339_opts(chrono::SecondsFormat::Millis, true));
|
||||
|
||||
if let Err(item::ItemOpError(_)) = item::SyncItem::items_insert(&db, &u, &it) {
|
||||
// Well, we should try twice...
|
||||
// TODO: make this more elegant (also handle differneces between db error and conflict)
|
||||
// (if we were ever to implement a conflict feature)
|
||||
if let Err(item::ItemOpError(_)) = item::SyncItem::items_insert(&db, &u, &it) {
|
||||
// Let's not fail just because one of them...
|
||||
// At least the client will know there's an error
|
||||
// (maybe mistakes it for conflict)
|
||||
it.updated_at = old_updated_at;
|
||||
resp.unsaved.push(it);
|
||||
}
|
||||
if let Err(item::ItemOpError(e)) = item::SyncItem::items_insert(&db, &u, &it) {
|
||||
// We can just return an error here
|
||||
return error_resp(Status::InternalServerError, vec![e]);
|
||||
} else {
|
||||
resp.saved_items.push(it);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue