Skip to content

Commit

Permalink
fix: create router for inexistent room
Browse files Browse the repository at this point in the history
  • Loading branch information
woody146 committed Jun 26, 2023
1 parent a69a849 commit 810116b
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/services/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,19 @@ export class RouterService extends BaseService {
mediaRouter.id = result.id;
mediaRouter.workerId = worker.id;
Object.assign(mediaRouter, data);
await this.dataSource.getRepository(MediaRouter).save(mediaRouter);
try {
await this.dataSource.getRepository(MediaRouter).save(mediaRouter);
} catch (e) {
// violates foreign key constraint because room doesn't exist
fetchApi({
host: worker.apiHost,
port: worker.apiPort,
path: '/routers/:routerId',
method: 'DELETE',
data: { routerId: result.id },
});
throw new ServiceError(404, 'Room not found');
}
return result;
}

Expand Down

0 comments on commit 810116b

Please sign in to comment.