Don't use 409 http status code for shape invalidation
We discussed using a 3xx code and in retrospect, I wish we had — it's a very common question in Discord about "what broke" with a shape invalidation — where there's nothing wrong. The problem is just that browser devtools put 4xx status codes fetches in the console so it looks like something went wrong.
Perhaps we can change this in a non-breaking way for v1? Thoughts?
One mitigation would be to put a note in the error message that "this is normal, ...".
205 Reset Content with no body is also an option maybe? 301/303 might also work
Ooo we missed 205 in the discussions last fall. That is nice. It is a "successful" response as in things are working normally, the client just needs to reset based on some server changes. No big deal folks!
While I like the idea of 205 as a 2xx code, it is against the spec to put a body in it and we might run into the same issues we ran into with 204 - I think always including a control message in the body is a good idea (currently the must-refetch control message). In that sense, if we think that "this is normal" we could even just go the 200 route?
The 3xx codes worry me slightly in that many clients and implementations will use their location header and other ways to perform redirects, whereas we want to detect the must-refetch message and then start requesting the new shape, so I'm slightly worried we run into an incompatibility with the HTTP spec with them, we should carefully consider them.
205 with a header?
hmm yeah, then 200 would be better. If we want to do this change now and be backwards compatible, these are the two bits of code to look at:
- https://github.com/electric-sql/electric/blob/4675201bbdea0cc23583e76126516c1f7d1941ce/packages/typescript-client/src/client.ts#L561
- https://github.com/electric-sql/electric/blob/4675201bbdea0cc23583e76126516c1f7d1941ce/packages/typescript-client/src/shape.ts#L173
We do check for the 409 immediately to start the refetch — so we could perhaps add a must-refetch header as well to give an early indicator that avoids needing to parse the body? And/or check always for must-fetch in the body.