How to get notified when the Sync Gateway refused my docs

130 views
Skip to first unread message

Jonas Schmid

unread,
Jul 15, 2015, 2:57:56 AM7/15/15
to mobile-c...@googlegroups.com
Hey guys,

I am playing with the Sync Gateway and the requireUser/requireRole rules.

I tried to delete a document from my iOS app which I am not allowed to delete:
  • I see the "throw" happens on the server side.
  • My local document has already been deleted
  • I do not get notified for this error
By looking at the code we clearly see that this error from the sync gateway is considered as "normal" because the user is not allowed to do that.

However, I can see cases where it could be beneficial to at least get notified. For example: 
  • After publishing my app I notice that a rule was not correctly written and allow user to do bad things. 
  • I update the sync function
  • I update the app
  • A user does not update the app and tries to do the "bad" thing
  • The app gets in a bad state and the user does not even now about it
Is my example to convoluted? Did I miss THE way to get notified when this type of error arrives?

Thanks!
Jonas

Jens Alfke

unread,
Jul 15, 2015, 12:19:53 PM7/15/15
to mobile-c...@googlegroups.com
Generally it’s assumed that the app and server should agree on validation, so that the app cannot produce a revision that the server rejects. In other words, the validation done by the server is to mostly protect against malicious clients trying to send bad data, and also to guard against bugs in legitimate apps.

If the app produces a revision the server rejects, it’s in kind of an awkward state, since the user could have made that change a long time ago (while offline). It’s a bad UX to have to say “Oh, that edit you saved this morning? I just realized it’s not valid, so do it over.” The app should have done its own validation at the point the user pressed Save, and presented the error then.

But you have a point that, if this did happen, the app might want to know about it. It would be pretty easy to have the replicator post a notification. (In general, I think there’s a need to have the replicator post finer-grained progress information, and this is a part of that.)

Could you file an issue requesting this, please?

—Jens

atom992

unread,
Jul 15, 2015, 1:02:13 PM7/15/15
to mobile-c...@googlegroups.com
I have the same issue when using couchbaselite-phonegap-plugin(1.1 with SG 1.1,REST API). and at the same time, I also want to know, How should I do on the CBL side. I can accept  the sync gateway's doc, but how should I do ? 
a) delete the CBL's conflict doc and let sync gateway sync the doc again?
the deletion will tiger the sync back to sync gateway from CBL? the version of doc in CBL will increase? 
b) Using the sync gateway's doc to update the CBL's doc?
the version of doc in CBL will increase? and this will cause other conflict(also if the doc's rev will generate by doc's value,but the rev will include 2 part,such as in CBL ,the rev is 3-f1f92da1ac57cb812b5352aca4272ff6 and in the sync gateway ,the rev is 5-f1f92da1ac57cb812b5352aca4272ff6)?

Jens Alfke

unread,
Jul 15, 2015, 1:11:54 PM7/15/15
to mobile-c...@googlegroups.com

On Jul 15, 2015, at 10:02 AM, atom992 <yangzi...@gmail.com> wrote:

I have the same issue when using couchbaselite-phonegap-plugin(1.1 with SG 1.1,REST API). and at the same time, I also want to know, How should I do on the CBL side. I can accept  the sync gateway's doc, but how should I do ? 
a) delete the CBL's conflict doc and let sync gateway sync the doc again?

You’re talking about conflicts, which are different. The previous message was about what happens when the Gateway’s sync function rejects a revision from the client.

We have documentation about resolving conflicts; have you read through it?

—Jens

atom992

unread,
Jul 15, 2015, 1:27:06 PM7/15/15
to mobile-c...@googlegroups.com


On Thursday, July 16, 2015 at 1:11:54 AM UTC+8, Jens Alfke wrote:

On Jul 15, 2015, at 10:02 AM, atom992 <yangzi...@gmail.com> wrote:

I have the same issue when using couchbaselite-phonegap-plugin(1.1 with SG 1.1,REST API). and at the same time, I also want to know, How should I do on the CBL side. I can accept  the sync gateway's doc, but how should I do ? 
a) delete the CBL's conflict doc and let sync gateway sync the doc again?

You’re talking about conflicts, which are different. The previous message was about what happens when the Gateway’s sync function rejects a revision from the client.

I think the Gateway’s sync function rejects a revision from the client will cause conflicts, and why I want to get notification, is I can handle the conflicts.
 

We have documentation about resolving conflicts; have you read through it?

can you give me the link,please?
 

—Jens

Jens Alfke

unread,
Jul 15, 2015, 2:48:31 PM7/15/15
to mobile-c...@googlegroups.com

On Jul 15, 2015, at 10:27 AM, atom992 <yangzi...@gmail.com> wrote:

can you give me the link,please?


—Jens

atom992

unread,
Jul 15, 2015, 6:39:35 PM7/15/15
to mobile-c...@googlegroups.com
Thank you very much.for REST API, I can do the same logic I see.

Jonas Schmid

unread,
Jul 16, 2015, 4:57:59 AM7/16/15
to mobile-c...@googlegroups.com

atom992

unread,
Jul 17, 2015, 7:58:57 AM7/17/15
to mobile-c...@googlegroups.com
If the replicator can post the reason of why sync gateway reject the doc at the same time, It will be better for CBL to handle the conflict depend on the error message.
Reply all
Reply to author
Forward
0 new messages