From bf842fa643a667063717e58c819a15b61841832e Mon Sep 17 00:00:00 2001 From: Andrew Bulat Date: Wed, 12 Feb 2025 06:14:40 +0000 Subject: [PATCH] Use more specific error codes for LiveObjects errors Resolves PUB-1011 --- .../liveobjects/batchcontextlivecounter.ts | 2 +- src/plugins/liveobjects/livecounter.ts | 18 ++++++------- src/plugins/liveobjects/livemap.ts | 26 +++++++++---------- src/plugins/liveobjects/liveobject.ts | 4 +-- src/plugins/liveobjects/liveobjects.ts | 4 +-- src/plugins/liveobjects/objectid.ts | 10 +++---- 6 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/plugins/liveobjects/batchcontextlivecounter.ts b/src/plugins/liveobjects/batchcontextlivecounter.ts index e61cd9d1c..3528c3ecb 100644 --- a/src/plugins/liveobjects/batchcontextlivecounter.ts +++ b/src/plugins/liveobjects/batchcontextlivecounter.ts @@ -33,7 +33,7 @@ export class BatchContextLiveCounter { // do an explicit type safety check here before negating the amount value, // so we don't unintentionally change the type sent by a user if (typeof amount !== 'number') { - throw new this._client.ErrorInfo('Counter value decrement should be a number', 40013, 400); + throw new this._client.ErrorInfo('Counter value decrement should be a number', 40003, 400); } this.increment(-amount); diff --git a/src/plugins/liveobjects/livecounter.ts b/src/plugins/liveobjects/livecounter.ts index c5a7be1bb..34b9ecf59 100644 --- a/src/plugins/liveobjects/livecounter.ts +++ b/src/plugins/liveobjects/livecounter.ts @@ -52,7 +52,7 @@ export class LiveCounter extends LiveObject const client = liveObjects.getClient(); if (typeof amount !== 'number' || !isFinite(amount)) { - throw new client.ErrorInfo('Counter value increment should be a valid number', 40013, 400); + throw new client.ErrorInfo('Counter value increment should be a valid number', 40003, 400); } const stateMessage = StateMessage.fromValues( @@ -77,7 +77,7 @@ export class LiveCounter extends LiveObject const client = liveObjects.getClient(); if (count !== undefined && (typeof count !== 'number' || !Number.isFinite(count))) { - throw new client.ErrorInfo('Counter value should be a valid number', 40013, 400); + throw new client.ErrorInfo('Counter value should be a valid number', 40003, 400); } const initialValueObj = LiveCounter.createInitialValueObject(count); @@ -150,7 +150,7 @@ export class LiveCounter extends LiveObject // do an explicit type safety check here before negating the amount value, // so we don't unintentionally change the type sent by a user if (typeof amount !== 'number' || !isFinite(amount)) { - throw new this._client.ErrorInfo('Counter value decrement should be a valid number', 40013, 400); + throw new this._client.ErrorInfo('Counter value decrement should be a valid number', 40003, 400); } return this.increment(-amount); @@ -163,7 +163,7 @@ export class LiveCounter extends LiveObject if (op.objectId !== this.getObjectId()) { throw new this._client.ErrorInfo( `Cannot apply state operation with objectId=${op.objectId}, to this LiveCounter with objectId=${this.getObjectId()}`, - 50000, + 92000, 500, ); } @@ -211,7 +211,7 @@ export class LiveCounter extends LiveObject default: throw new this._client.ErrorInfo( `Invalid ${op.action} op for LiveCounter objectId=${this.getObjectId()}`, - 50000, + 92000, 500, ); } @@ -226,7 +226,7 @@ export class LiveCounter extends LiveObject if (stateObject.objectId !== this.getObjectId()) { throw new this._client.ErrorInfo( `Invalid state object: state object objectId=${stateObject.objectId}; LiveCounter objectId=${this.getObjectId()}`, - 50000, + 92000, 500, ); } @@ -236,7 +236,7 @@ export class LiveCounter extends LiveObject if (stateObject.createOp.objectId !== this.getObjectId()) { throw new this._client.ErrorInfo( `Invalid state object: state object createOp objectId=${stateObject.createOp?.objectId}; LiveCounter objectId=${this.getObjectId()}`, - 50000, + 92000, 500, ); } @@ -244,7 +244,7 @@ export class LiveCounter extends LiveObject if (stateObject.createOp.action !== StateOperationAction.COUNTER_CREATE) { throw new this._client.ErrorInfo( `Invalid state object: state object createOp action=${stateObject.createOp?.action}; LiveCounter objectId=${this.getObjectId()}`, - 50000, + 92000, 500, ); } @@ -308,7 +308,7 @@ export class LiveCounter extends LiveObject private _throwNoPayloadError(op: StateOperation): void { throw new this._client.ErrorInfo( `No payload found for ${op.action} op for LiveCounter objectId=${this.getObjectId()}`, - 50000, + 92000, 500, ); } diff --git a/src/plugins/liveobjects/livemap.ts b/src/plugins/liveobjects/livemap.ts index 6b9f60e80..637c5eeed 100644 --- a/src/plugins/liveobjects/livemap.ts +++ b/src/plugins/liveobjects/livemap.ts @@ -143,7 +143,7 @@ export class LiveMap extends LiveObject extends LiveObject extends LiveObject LiveMap.validateKeyValue(liveObjects, key, value)); @@ -368,7 +368,7 @@ export class LiveMap extends LiveObject extends LiveObject extends LiveObject extends LiveObject extends LiveObject extends LiveObject extends LiveObject extends LiveObject extends LiveObject extends LiveObject