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