Skip to content

Commit afd3273

Browse files
committed
fix: returned http api status codes on error
1 parent 3ff013d commit afd3273

5 files changed

Lines changed: 73 additions & 46 deletions

File tree

meteor/server/api/rest/v1/blueprints.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,12 @@ class BlueprintsServerAPI implements BlueprintsRestAPI {
3232
const blueprint = await Blueprints.findOneAsync(blueprintId)
3333
if (!blueprint) {
3434
return ClientAPI.responseError(
35-
UserError.from(new Error(`Blueprint ${blueprintId} not found`), UserErrorMessage.BlueprintNotFound),
36-
404
35+
UserError.from(
36+
new Error(`Blueprint ${blueprintId} not found`),
37+
UserErrorMessage.BlueprintNotFound,
38+
undefined,
39+
404
40+
)
3741
)
3842
}
3943

meteor/server/api/rest/v1/buckets.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,12 @@ export class BucketsServerAPI implements BucketsRestAPI {
3737
const bucket = await Buckets.findOneAsync(bucketId, { projection: { _id: 1, name: 1, studioId: 1 } })
3838
if (!bucket) {
3939
return ClientAPI.responseError(
40-
UserError.from(new Error(`Bucket ${bucketId} not found`), UserErrorMessage.BucketNotFound),
41-
404
40+
UserError.from(
41+
new Error(`Bucket ${bucketId} not found`),
42+
UserErrorMessage.BucketNotFound,
43+
undefined,
44+
404
45+
)
4246
)
4347
}
4448
return ClientAPI.responseSuccess(APIBucketFrom(bucket))

meteor/server/api/rest/v1/devices.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@ class DevicesServerAPI implements DevicesRestAPI {
3939
return ClientAPI.responseError(
4040
UserError.from(
4141
new Error(`Device ${deviceId} does not exist`),
42-
UserErrorMessage.PeripheralDeviceNotFound
43-
),
44-
404
42+
UserErrorMessage.PeripheralDeviceNotFound,
43+
undefined,
44+
404
45+
)
4546
)
4647
return ClientAPI.responseSuccess(APIPeripheralDeviceFrom(device))
4748
}
@@ -57,9 +58,10 @@ class DevicesServerAPI implements DevicesRestAPI {
5758
return ClientAPI.responseError(
5859
UserError.from(
5960
new Error(`Device ${deviceId} does not exist`),
60-
UserErrorMessage.PeripheralDeviceNotFound
61-
),
62-
404
61+
UserErrorMessage.PeripheralDeviceNotFound,
62+
undefined,
63+
404
64+
)
6365
)
6466

6567
switch (action.type) {

meteor/server/api/rest/v1/playlists.ts

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,19 @@ class PlaylistsServerAPI implements PlaylistsRestAPI {
133133
return ClientAPI.responseError(
134134
UserError.from(
135135
new Error(`Rundown playlist does not exist`),
136-
UserErrorMessage.RundownPlaylistNotFound
137-
),
138-
404
136+
UserErrorMessage.RundownPlaylistNotFound,
137+
undefined,
138+
404
139+
)
139140
)
140141
if (rundownPlaylist.currentPartInfo === null)
141142
return ClientAPI.responseError(
142-
UserError.from(Error(`No active Part in ${rundownPlaylistId}`), UserErrorMessage.PartNotFound),
143-
412
143+
UserError.from(
144+
Error(`No active Part in ${rundownPlaylistId}`),
145+
UserErrorMessage.PartNotFound,
146+
undefined,
147+
412
148+
)
144149
)
145150

146151
const result = await ServerClientAPI.runUserActionInLogForPlaylistOnWorker(
@@ -172,25 +177,28 @@ class PlaylistsServerAPI implements PlaylistsRestAPI {
172177
return ClientAPI.responseError(
173178
UserError.from(
174179
new Error(`Rundown playlist does not exist`),
175-
UserErrorMessage.RundownPlaylistNotFound
176-
),
177-
404
180+
UserErrorMessage.RundownPlaylistNotFound,
181+
undefined,
182+
404
183+
)
178184
)
179185
if (!rundownPlaylist.activationId)
180186
return ClientAPI.responseError(
181187
UserError.from(
182188
new Error(`Rundown playlist ${rundownPlaylistId} is not currently active`),
183-
UserErrorMessage.InactiveRundown
184-
),
185-
412
189+
UserErrorMessage.InactiveRundown,
190+
undefined,
191+
412
192+
)
186193
)
187194
if (!rundownPlaylist.currentPartInfo)
188195
return ClientAPI.responseError(
189196
UserError.from(
190197
new Error(`Rundown playlist ${rundownPlaylistId} must be playing`),
191-
UserErrorMessage.NoCurrentPart
192-
),
193-
412
198+
UserErrorMessage.NoCurrentPart,
199+
undefined,
200+
412
201+
)
194202
)
195203

196204
return ServerClientAPI.runUserActionInLogForPlaylistOnWorker(
@@ -214,8 +222,7 @@ class PlaylistsServerAPI implements PlaylistsRestAPI {
214222
)
215223
} else {
216224
return ClientAPI.responseError(
217-
UserError.from(new Error(`No adLib with Id ${adLibId}`), UserErrorMessage.AdlibNotFound),
218-
412
225+
UserError.from(new Error(`No adLib with Id ${adLibId}`), UserErrorMessage.AdlibNotFound, undefined, 412)
219226
)
220227
}
221228
}
@@ -242,17 +249,22 @@ class PlaylistsServerAPI implements PlaylistsRestAPI {
242249
])
243250
if (!bucket) {
244251
return ClientAPI.responseError(
245-
UserError.from(new Error(`Bucket ${bucketId} not found`), UserErrorMessage.BucketNotFound),
246-
412
252+
UserError.from(
253+
new Error(`Bucket ${bucketId} not found`),
254+
UserErrorMessage.BucketNotFound,
255+
undefined,
256+
412
257+
)
247258
)
248259
}
249260
if (!bucketAdlib && !bucketAdlibAction) {
250261
return ClientAPI.responseError(
251262
UserError.from(
252263
new Error(`No adLib with Id ${externalId}, in bucket ${bucketId}`),
253-
UserErrorMessage.AdlibNotFound
254-
),
255-
412
264+
UserErrorMessage.AdlibNotFound,
265+
undefined,
266+
412
267+
)
256268
)
257269
}
258270

@@ -477,17 +489,19 @@ class PlaylistsServerAPI implements PlaylistsRestAPI {
477489
return ClientAPI.responseError(
478490
UserError.from(
479491
Error(`Rundown playlist ${rundownPlaylistId} does not exist`),
480-
UserErrorMessage.RundownPlaylistNotFound
481-
),
482-
412
492+
UserErrorMessage.RundownPlaylistNotFound,
493+
undefined,
494+
412
495+
)
483496
)
484497
if (!rundownPlaylist.currentPartInfo?.partInstanceId || !rundownPlaylist.activationId)
485498
return ClientAPI.responseError(
486499
UserError.from(
487500
new Error(`Rundown playlist ${rundownPlaylistId} is not currently active`),
488-
UserErrorMessage.InactiveRundown
489-
),
490-
412
501+
UserErrorMessage.InactiveRundown,
502+
undefined,
503+
412
504+
)
491505
)
492506

493507
return ServerClientAPI.runUserActionInLogForPlaylistOnWorker(

meteor/server/api/rest/v1/studios.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -256,24 +256,28 @@ class StudiosServerAPI implements StudiosRestAPI {
256256
const studio = await Studios.findOneAsync(studioId)
257257
if (!studio)
258258
return ClientAPI.responseError(
259-
UserError.from(new Error(`Studio does not exist`), UserErrorMessage.StudioNotFound),
260-
404
259+
UserError.from(new Error(`Studio does not exist`), UserErrorMessage.StudioNotFound, undefined, 404)
261260
)
262261

263262
const device = await PeripheralDevices.findOneAsync(deviceId)
264263
if (!device)
265264
return ClientAPI.responseError(
266-
UserError.from(new Error(`Studio does not exist`), UserErrorMessage.PeripheralDeviceNotFound),
267-
404
265+
UserError.from(
266+
new Error(`Studio does not exist`),
267+
UserErrorMessage.PeripheralDeviceNotFound,
268+
undefined,
269+
404
270+
)
268271
)
269272

270273
if (device.studioAndConfigId !== undefined && device.studioAndConfigId.studioId !== studio._id) {
271274
return ClientAPI.responseError(
272275
UserError.from(
273276
new Error(`Device already attached to studio`),
274-
UserErrorMessage.DeviceAlreadyAttachedToStudio
275-
),
276-
412
277+
UserErrorMessage.DeviceAlreadyAttachedToStudio,
278+
undefined,
279+
412
280+
)
277281
)
278282
}
279283

@@ -318,8 +322,7 @@ class StudiosServerAPI implements StudiosRestAPI {
318322
const studio = await Studios.findOneAsync(studioId)
319323
if (!studio)
320324
return ClientAPI.responseError(
321-
UserError.from(new Error(`Studio does not exist`), UserErrorMessage.StudioNotFound),
322-
404
325+
UserError.from(new Error(`Studio does not exist`), UserErrorMessage.StudioNotFound, undefined, 404)
323326
)
324327
await PeripheralDevices.updateAsync(
325328
{

0 commit comments

Comments
 (0)