@electric-sql/client 0.6.4 → 0.6.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@electric-sql/client",
3
- "version": "0.6.4",
3
+ "version": "0.6.5",
4
4
  "description": "Postgres everywhere - your data, in sync, wherever you need it.",
5
5
  "type": "module",
6
6
  "main": "dist/cjs/index.cjs",
package/src/client.ts CHANGED
@@ -159,6 +159,7 @@ export class ShapeStream<T extends Row<unknown> = Row>
159
159
  #connected: boolean = false
160
160
  #shapeId?: string
161
161
  #schema?: Schema
162
+ #error?: unknown
162
163
 
163
164
  constructor(options: ShapeStreamOptions<GetExtensions<T>>) {
164
165
  validateOptions(options)
@@ -193,6 +194,10 @@ export class ShapeStream<T extends Row<unknown> = Row>
193
194
  return this.#isUpToDate
194
195
  }
195
196
 
197
+ get error() {
198
+ return this.#error
199
+ }
200
+
196
201
  async start() {
197
202
  this.#isUpToDate = false
198
203
 
@@ -232,13 +237,7 @@ export class ShapeStream<T extends Row<unknown> = Row>
232
237
  } catch (e) {
233
238
  if (e instanceof FetchBackoffAbortError) break // interrupted
234
239
  if (!(e instanceof FetchError)) throw e // should never happen
235
- if (e.status == 400) {
236
- // The request is invalid, most likely because the shape has been deleted.
237
- // We should start from scratch, this will force the shape to be recreated.
238
- this.#reset()
239
- await this.#publish(e.json as Message<T>[])
240
- continue
241
- } else if (e.status == 409) {
240
+ if (e.status == 409) {
242
241
  // Upon receiving a 409, we should start from scratch
243
242
  // with the newly provided shape ID
244
243
  const newShapeId = e.headers[SHAPE_ID_HEADER]
@@ -250,7 +249,8 @@ export class ShapeStream<T extends Row<unknown> = Row>
250
249
  this.#sendErrorToUpToDateSubscribers(e)
251
250
  this.#sendErrorToSubscribers(e)
252
251
 
253
- // 400 errors are not actionable without additional user input, so we're throwing them.
252
+ // 400 errors are not actionable without additional user input,
253
+ // so we exit the loop
254
254
  throw e
255
255
  }
256
256
  }
@@ -301,6 +301,8 @@ export class ShapeStream<T extends Row<unknown> = Row>
301
301
  }
302
302
  }
303
303
  }
304
+ } catch (err) {
305
+ this.#error = err
304
306
  } finally {
305
307
  this.#connected = false
306
308
  }