Skip to content

Commit 77ab200

Browse files
authored
Merge pull request #2290 from ably/fix/liveobjects-92000-status
Report error 92000 with HTTP status 400, not 500
2 parents 25058b0 + 17b6929 commit 77ab200

3 files changed

Lines changed: 19 additions & 19 deletions

File tree

src/plugins/liveobjects/livecounter.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export class LiveCounter extends LiveObject<LiveCounterData, LiveCounterUpdate>
105105
throw new this._client.ErrorInfo(
106106
`Cannot apply object operation with objectId=${op.objectId}, to this LiveCounter with objectId=${this.getObjectId()}`,
107107
92000,
108-
500,
108+
400,
109109
);
110110
}
111111

@@ -180,14 +180,14 @@ export class LiveCounter extends LiveObject<LiveCounterData, LiveCounterUpdate>
180180
overrideWithObjectState(objectMessage: ObjectMessage): LiveCounterUpdate | LiveObjectUpdateNoop {
181181
const objectState = objectMessage.object;
182182
if (objectState == null) {
183-
throw new this._client.ErrorInfo(`Missing object state; LiveCounter objectId=${this.getObjectId()}`, 92000, 500);
183+
throw new this._client.ErrorInfo(`Missing object state; LiveCounter objectId=${this.getObjectId()}`, 92000, 400);
184184
}
185185

186186
if (objectState.objectId !== this.getObjectId()) {
187187
throw new this._client.ErrorInfo(
188188
`Invalid object state: object state objectId=${objectState.objectId}; LiveCounter objectId=${this.getObjectId()}`,
189189
92000,
190-
500,
190+
400,
191191
);
192192
}
193193

@@ -197,15 +197,15 @@ export class LiveCounter extends LiveObject<LiveCounterData, LiveCounterUpdate>
197197
throw new this._client.ErrorInfo(
198198
`Invalid object state: object state createOp objectId=${objectState.createOp?.objectId}; LiveCounter objectId=${this.getObjectId()}`,
199199
92000,
200-
500,
200+
400,
201201
);
202202
}
203203

204204
if (objectState.createOp.action !== ObjectOperationAction.COUNTER_CREATE) {
205205
throw new this._client.ErrorInfo(
206206
`Invalid object state: object state createOp action=${objectState.createOp?.action}; LiveCounter objectId=${this.getObjectId()}`,
207207
92000,
208-
500,
208+
400,
209209
);
210210
}
211211
}

src/plugins/liveobjects/livemap.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ export class LiveMap<T extends Record<string, Value> = Record<string, Value>>
301301
throw new this._client.ErrorInfo(
302302
`Cannot apply object operation with objectId=${op.objectId}, to this LiveMap with objectId=${this.getObjectId()}`,
303303
92000,
304-
500,
304+
400,
305305
);
306306
}
307307

@@ -390,22 +390,22 @@ export class LiveMap<T extends Record<string, Value> = Record<string, Value>>
390390
overrideWithObjectState(objectMessage: ObjectMessage): LiveMapUpdate<T> | LiveObjectUpdateNoop {
391391
const objectState = objectMessage.object;
392392
if (objectState == null) {
393-
throw new this._client.ErrorInfo(`Missing object state; LiveMap objectId=${this.getObjectId()}`, 92000, 500);
393+
throw new this._client.ErrorInfo(`Missing object state; LiveMap objectId=${this.getObjectId()}`, 92000, 400);
394394
}
395395

396396
if (objectState.objectId !== this.getObjectId()) {
397397
throw new this._client.ErrorInfo(
398398
`Invalid object state: object state objectId=${objectState.objectId}; LiveMap objectId=${this.getObjectId()}`,
399399
92000,
400-
500,
400+
400,
401401
);
402402
}
403403

404404
if (objectState.map?.semantics !== this._semantics) {
405405
throw new this._client.ErrorInfo(
406406
`Invalid object state: object state map semantics=${objectState.map?.semantics}; LiveMap semantics=${this._semantics}`,
407407
92000,
408-
500,
408+
400,
409409
);
410410
}
411411

@@ -415,23 +415,23 @@ export class LiveMap<T extends Record<string, Value> = Record<string, Value>>
415415
throw new this._client.ErrorInfo(
416416
`Invalid object state: object state createOp objectId=${objectState.createOp?.objectId}; LiveMap objectId=${this.getObjectId()}`,
417417
92000,
418-
500,
418+
400,
419419
);
420420
}
421421

422422
if (objectState.createOp.action !== ObjectOperationAction.MAP_CREATE) {
423423
throw new this._client.ErrorInfo(
424424
`Invalid object state: object state createOp action=${objectState.createOp?.action}; LiveMap objectId=${this.getObjectId()}`,
425425
92000,
426-
500,
426+
400,
427427
);
428428
}
429429

430430
if (objectState.createOp.mapCreate?.semantics !== this._semantics) {
431431
throw new this._client.ErrorInfo(
432432
`Invalid object state: object state createOp map semantics=${objectState.createOp.mapCreate?.semantics}; LiveMap semantics=${this._semantics}`,
433433
92000,
434-
500,
434+
400,
435435
);
436436
}
437437
}
@@ -738,7 +738,7 @@ export class LiveMap<T extends Record<string, Value> = Record<string, Value>>
738738
throw new this._client.ErrorInfo(
739739
`Cannot apply MAP_CREATE op on LiveMap objectId=${this.getObjectId()}; map's semantics=${this._semantics}, but op expected ${mapCreate?.semantics}`,
740740
92000,
741-
500,
741+
400,
742742
);
743743
}
744744

@@ -781,7 +781,7 @@ export class LiveMap<T extends Record<string, Value> = Record<string, Value>>
781781
throw new ErrorInfo(
782782
`Invalid object data for MAP_SET op on objectId=${this.getObjectId()} on key="${op.key}"`,
783783
92000,
784-
500,
784+
400,
785785
);
786786
}
787787

src/plugins/liveobjects/objectid.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,26 +50,26 @@ export class ObjectId {
5050
*/
5151
static fromString(client: BaseClient, objectId: string | null | undefined): ObjectId {
5252
if (client.Utils.isNil(objectId)) {
53-
throw new client.ErrorInfo('Invalid object id string', 92000, 500);
53+
throw new client.ErrorInfo('Invalid object id string', 92000, 400);
5454
}
5555

5656
// RTO6b1
5757
const [type, rest] = objectId.split(':');
5858
if (!type || !rest) {
59-
throw new client.ErrorInfo('Invalid object id string', 92000, 500);
59+
throw new client.ErrorInfo('Invalid object id string', 92000, 400);
6060
}
6161

6262
if (!['map', 'counter'].includes(type)) {
63-
throw new client.ErrorInfo(`Invalid object type in object id: ${objectId}`, 92000, 500);
63+
throw new client.ErrorInfo(`Invalid object type in object id: ${objectId}`, 92000, 400);
6464
}
6565

6666
const [hash, msTimestamp] = rest.split('@');
6767
if (!hash || !msTimestamp) {
68-
throw new client.ErrorInfo('Invalid object id string', 92000, 500);
68+
throw new client.ErrorInfo('Invalid object id string', 92000, 400);
6969
}
7070

7171
if (!Number.isInteger(Number.parseInt(msTimestamp))) {
72-
throw new client.ErrorInfo('Invalid object id string', 92000, 500);
72+
throw new client.ErrorInfo('Invalid object id string', 92000, 400);
7373
}
7474

7575
return new ObjectId(type as LiveObjectType, hash, Number.parseInt(msTimestamp));

0 commit comments

Comments
 (0)