Skip to content

Commit f7721da

Browse files
committed
refactor: enhance error handling with type safety in connection use cases
1 parent f6a358f commit f7721da

3 files changed

Lines changed: 9 additions & 8 deletions

File tree

backend/src/entities/connection/connection.controller.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -536,10 +536,11 @@ export class ConnectionController {
536536
};
537537
try {
538538
await validateCreateConnectionData(inputData);
539-
} catch (e) {
539+
} catch (e: unknown) {
540+
const err = e as { response?: { message?: string }; message?: string };
540541
return {
541542
result: false,
542-
message: e?.response?.message || e?.message || Messages.CONNECTION_TYPE_INVALID,
543+
message: err?.response?.message || err?.message || Messages.CONNECTION_TYPE_INVALID,
543544
};
544545
}
545546
const result = await this.testConnectionUseCase.execute(inputData, InTransactionEnum.OFF);

backend/src/entities/connection/use-cases/find-all-users-in-connection.use.case.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { UserEntity } from '../../user/user.entity.js';
77
import { buildFoundUserDto } from '../../user/utils/build-found-user.dto.js';
88
import { IFindUsersInConnection } from './use-cases.interfaces.js';
99

10+
type UserWithoutRelations = Omit<UserEntity, 'connections' | 'groups'>;
11+
1012
@Injectable()
1113
export class FindAllUsersInConnectionUseCase
1214
extends AbstractUseCase<string, Array<FoundUserDto>>
@@ -20,10 +22,8 @@ export class FindAllUsersInConnectionUseCase
2022
}
2123

2224
protected async implementation(connectionId: string): Promise<Array<FoundUserDto>> {
23-
const userInConnection = await this._dbContext.userRepository.findAllUsersInConnection(connectionId);
24-
return userInConnection.map((user) => {
25-
//todo fix type after repository types are fixed
26-
return buildFoundUserDto(user as UserEntity);
27-
});
25+
const userInConnection: UserWithoutRelations[] =
26+
await this._dbContext.userRepository.findAllUsersInConnection(connectionId);
27+
return userInConnection.map((user) => buildFoundUserDto(user as UserEntity));
2828
}
2929
}

backend/src/entities/connection/use-cases/find-one-connection.use.case.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export class FindOneConnectionUseCase
8585
if (filteredConnection.masterEncryption && inputData.masterPwd && accessLevel !== AccessLevelEnum.none) {
8686
try {
8787
filteredConnection = Encryptor.decryptConnectionCredentials(connection, inputData.masterPwd);
88-
} catch (e) {
88+
} catch (e: unknown) {
8989
console.error('-> Error decrypting connection credentials', e);
9090
throw new HttpException(
9191
{

0 commit comments

Comments
 (0)