Skip to content

Commit

Permalink
Merge pull request #727 from rocket-admin/backend_development
Browse files Browse the repository at this point in the history
refactor: Handle unhandled errors in company registration, user invit…
  • Loading branch information
Artuomka authored Jul 9, 2024
2 parents 72b483f + a672cb3 commit bfa740c
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ export class ImportCSVInTableUseCase
);
}

if (connection.isTestConnection) {
throw new HttpException(
{
message: Messages.CSV_IMPORT_DISABLED_FOR_TEST_CONNECTIONS,
},
HttpStatus.BAD_REQUEST,
);
}

const foundTableSettings = await this._dbContext.tableSettingsRepository.findTableSettings(connectionId, tableName);

if (foundTableSettings?.allow_csv_import === false) {
Expand Down
6 changes: 6 additions & 0 deletions backend/src/exceptions/text/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export const Messages = {
CSV_EXPORT_DISABLED: 'CSV export is disabled',
CSV_IMPORT_FAILED: 'CSV import failed',
CSV_IMPORT_DISABLED: 'CSV import is disabled',
CSV_IMPORT_DISABLED_FOR_TEST_CONNECTIONS: 'CSV import is disabled for test connections',
DATABASE_MISSING: 'Database is missing',
DELETE_ROW_FAILED: 'Row deletion failed',
DESCRIPTION_MISSING: 'Description is missing',
Expand Down Expand Up @@ -133,6 +134,11 @@ export const Messages = {
FAILED_UPDATE_TABLE_SETTINGS: 'Failed to update table settings. ',
FIELD_MUST_BE_SORTABLE: (fieldName: string) =>
`The field "${fieldName}" must be included in sortable fields in table settings`,
FAILED_REGISTER_COMPANY_AND_INVITE_USER_IN_GROUP_UNHANDLED_ERROR: `Failed to register company and invite user in group. Please contact our support team.`,
FAILED_INVITE_USER_IN_COMPANY_UNHANDLED_ERROR: `Failed to invite user in company. Please contact our support team.`,
FAILED_REMOVE_USER_FROM_COMPANY_UNHANDLED_ERROR: `Failed to remove user from company. Please contact our support team.`,
FAILED_REVOKE_USER_INVITATION_UNHANDLED_ERROR: `Failed to revoke user invitation. Please contact our support team.`,
FAILED_SEND_INVITATION_SAAS_UNHANDLED_ERROR: `Failed to send user invitation notification. Please contact our support team.`,
GROUP_NAME_UNIQUE: 'Group title must be unique',
GROUP_NOT_FOUND: 'Group with specified parameters not found',
GROUP_NOT_FROM_THIS_CONNECTION: 'This group does not belong to this connection',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ export class SaasCompanyGatewayService extends BaseSaasGatewayService {
gitHubId,
});

if (registrationResult.status > 299) {
throw new HttpException(
{
message: Messages.FAILED_REGISTER_COMPANY_AND_INVITE_USER_IN_GROUP_UNHANDLED_ERROR,
originalMessage: registrationResult?.body?.message ? registrationResult.body.message : undefined,
},
registrationResult.status || 500,
);
}

if (isObjectEmpty(registrationResult.body)) {
return null;
}
Expand Down Expand Up @@ -60,6 +70,15 @@ export class SaasCompanyGatewayService extends BaseSaasGatewayService {
userRole: userRole,
inviterId: inviterId,
});
if (registrationResult.status > 299) {
throw new HttpException(
{
message: Messages.FAILED_INVITE_USER_IN_COMPANY_UNHANDLED_ERROR,
originalMessage: registrationResult?.body?.message ? registrationResult.body.message : undefined,
},
registrationResult.status,
);
}
if (isObjectEmpty(registrationResult.body)) {
return null;
}
Expand All @@ -74,6 +93,15 @@ export class SaasCompanyGatewayService extends BaseSaasGatewayService {
userId: userId,
companyId: companyId,
});
if (removalResult.status > 299) {
throw new HttpException(
{
message: Messages.FAILED_REMOVE_USER_FROM_COMPANY_UNHANDLED_ERROR,
originalMessage: removalResult?.body?.message ? removalResult.body.message : undefined,
},
removalResult.status,
);
}
if (isObjectEmpty(removalResult.body)) {
return null;
}
Expand All @@ -90,6 +118,15 @@ export class SaasCompanyGatewayService extends BaseSaasGatewayService {
verification_string: verification_string,
companyId: companyId,
});
if (removalResult.status > 299) {
throw new HttpException(
{
message: Messages.FAILED_REVOKE_USER_INVITATION_UNHANDLED_ERROR,
originalMessage: removalResult?.body?.message ? removalResult.body.message : undefined,
},
removalResult.status,
);
}
if (isObjectEmpty(removalResult.body)) {
return null;
}
Expand All @@ -113,13 +150,22 @@ export class SaasCompanyGatewayService extends BaseSaasGatewayService {
inviterId: string,
verificationString: string,
): Promise<void> {
await this.sendRequestToSaaS(`/webhook/company/invitation`, 'POST', {
const { body, status } = await this.sendRequestToSaaS(`/webhook/company/invitation`, 'POST', {
userEmail: newUserEmail,
companyId: companyId,
userRole: userRole,
inviterId: inviterId,
verificationString: verificationString,
});
if (status > 299) {
throw new HttpException(
{
message: Messages.FAILED_SEND_INVITATION_SAAS_UNHANDLED_ERROR,
originalMessage: body?.message ? body.message : undefined,
},
status,
);
}
}

public async invitationAcceptedWebhook(
Expand Down

0 comments on commit bfa740c

Please sign in to comment.