@@ -70,21 +70,22 @@ export class ClusterService implements IClusterServiceServer {
70
70
try {
71
71
// check if the name or URL are already registered/in use
72
72
const req = call . request . toObject ( ) ;
73
- await Promise . all ( [
74
- async ( ) => {
75
- const oldCluster = await this . clusterDB . findByName ( req . name ) ;
76
- if ( ! oldCluster ) {
77
- throw new GRPCError ( grpc . status . ALREADY_EXISTS , `a WorkspaceCluster with name ${ req . name } already exists in the DB` ) ;
78
- }
79
- } ,
80
- async ( ) => {
81
- const oldCluster = await this . clusterDB . findFiltered ( { url : req . url } ) ;
82
- if ( ! oldCluster ) {
83
- throw new GRPCError ( grpc . status . ALREADY_EXISTS , `a WorkspaceCluster with url ${ req . url } already exists in the DB` ) ;
84
- }
85
- }
73
+
74
+ const clusterByNamePromise = this . clusterDB . findByName ( req . name ) ;
75
+ const clusterByUrlPromise = this . clusterDB . findFiltered ( { url : req . url } )
76
+
77
+ const [ clusterByName , clusterByUrl ] = await Promise . all ( [
78
+ clusterByNamePromise ,
79
+ clusterByUrlPromise
86
80
] ) ;
87
81
82
+ if ( ! ! clusterByName ) {
83
+ throw new GRPCError ( grpc . status . ALREADY_EXISTS , `a WorkspaceCluster with name ${ req . name } already exists in the DB` ) ;
84
+ }
85
+ if ( Array . isArray ( clusterByUrl ) && clusterByUrl . length > 0 ) {
86
+ throw new GRPCError ( grpc . status . ALREADY_EXISTS , `a WorkspaceCluster with url ${ req . url } already exists in the DB` ) ;
87
+ }
88
+
88
89
// store the ws-manager into the database
89
90
let perfereability = Preferability . NONE ;
90
91
let govern = false ;
@@ -154,7 +155,7 @@ export class ClusterService implements IClusterServiceServer {
154
155
const req = call . request . toObject ( ) ;
155
156
const cluster = await this . clusterDB . findByName ( req . name ) ;
156
157
if ( ! cluster ) {
157
- throw new GRPCError ( grpc . status . ALREADY_EXISTS , `a WorkspaceCluster with name ${ req . name } already exists in the DB!` ) ;
158
+ throw new GRPCError ( grpc . status . NOT_FOUND , `a WorkspaceCluster with name ${ req . name } does not exist in the DB!` ) ;
158
159
}
159
160
160
161
if ( call . request . hasMaxScore ( ) ) {
0 commit comments