electric icon indicating copy to clipboard operation
electric copied to clipboard

Don't use 409 http status code for shape invalidation

Open KyleAMathews opened this issue 8 months ago • 6 comments

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?

KyleAMathews avatar Apr 22 '25 18:04 KyleAMathews

One mitigation would be to put a note in the error message that "this is normal, ...".

thruflo avatar Apr 23 '25 07:04 thruflo

205 Reset Content with no body is also an option maybe? 301/303 might also work

icehaunter avatar Apr 23 '25 09:04 icehaunter

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!

KyleAMathews avatar Apr 23 '25 13:04 KyleAMathews

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.

msfstef avatar Apr 24 '25 08:04 msfstef

205 with a header?

thruflo avatar Apr 24 '25 10:04 thruflo

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.

KyleAMathews avatar Apr 24 '25 17:04 KyleAMathews