Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ export const DeleteDomain: React.FC<{ domain: Domain }> = ({ domain }) => {
toast.success(`Domain ${domain.name} deleted`);
router.replace("/domains");
},
onError: (error) => {
toast.error(`Failed to delete domain: ${error.message}`);
},
},
);
}
Expand Down
4 changes: 4 additions & 0 deletions apps/web/src/app/(dashboard)/domains/domain-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import React from "react";
import { StatusIndicator } from "./status-indicator";
import { DomainStatusBadge } from "./domain-badge";
import Spinner from "@usesend/ui/src/spinner";
import { DeleteDomain } from "./[domainId]/delete-domain";

export default function DomainsList() {
const domainsQuery = api.domain.domains.useQuery();
Expand Down Expand Up @@ -116,6 +117,9 @@ const DomainItem: React.FC<{ domain: Domain }> = ({ domain }) => {
/>
</div>
</div>
<div className="flex items-center">
<DeleteDomain domain={domain} />
</div>
</div>
</div>
</div>
Expand Down
73 changes: 55 additions & 18 deletions apps/web/src/server/aws/ses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,30 +150,67 @@ export async function deleteDomain(
const sesClient = getSesClient(region);

if (sesTenantId) {
const tenantResourceAssociationCommand =
new DeleteTenantResourceAssociationCommand({
TenantName: sesTenantId,
ResourceArn: await getIdentityArn(domain, region),
});
try {
const tenantResourceAssociationCommand =
new DeleteTenantResourceAssociationCommand({
TenantName: sesTenantId,
ResourceArn: await getIdentityArn(domain, region),
});

const tenantResourceAssociationResponse = await sesClient.send(
tenantResourceAssociationCommand
);

const tenantResourceAssociationResponse = await sesClient.send(
tenantResourceAssociationCommand
);
if (tenantResourceAssociationResponse.$metadata.httpStatusCode !== 200) {
logger.error(
{ domain, region, sesTenantId, tenantResourceAssociationResponse },
"[ses.deleteDomain] non-200 from DeleteTenantResourceAssociation"
);
throw new Error("Failed to delete tenant resource association");
}
} catch (error: any) {
if (error?.name === "NotFoundException") {
logger.warn(
{ domain, region, sesTenantId, errorName: error.name },
"[ses.deleteDomain] tenant association already gone, continuing"
);
} else {
logger.error(
{ err: error, domain, region, sesTenantId },
"[ses.deleteDomain] DeleteTenantResourceAssociation failed"
);
throw error;
}
}
}

if (tenantResourceAssociationResponse.$metadata.httpStatusCode !== 200) {
try {
const command = new DeleteEmailIdentityCommand({
EmailIdentity: domain,
});
const response = await sesClient.send(command);
if (response.$metadata.httpStatusCode !== 200) {
logger.error(
{ tenantResourceAssociationResponse },
"Failed to delete tenant resource association"
{ domain, region, response },
"[ses.deleteDomain] non-200 from DeleteEmailIdentity"
);
throw new Error("Failed to delete tenant resource association");
return false;
}
return true;
} catch (error: any) {
Comment thread
coderabbitai[bot] marked this conversation as resolved.
if (error?.name === "NotFoundException") {
logger.warn(
{ domain, region, errorName: error.name },
"[ses.deleteDomain] identity already gone on SES, continuing"
);
return true;
}
logger.error(
{ err: error, domain, region },
"[ses.deleteDomain] DeleteEmailIdentity failed"
);
throw error;
}

const command = new DeleteEmailIdentityCommand({
EmailIdentity: domain,
});
const response = await sesClient.send(command);
return response.$metadata.httpStatusCode === 200;
}

export async function getDomainIdentity(domain: string, region: string) {
Expand Down