Skip to content

Commit 552f827

Browse files
authored
Merge pull request #2001 from appwrite/fix-adding-domains
Fix: unable to add domain if apex already exists
2 parents ef61b18 + 7f678cf commit 552f827

File tree

3 files changed

+31
-20
lines changed
  • src/routes/(console)/project-[region]-[project]

3 files changed

+31
-20
lines changed

src/routes/(console)/project-[region]-[project]/functions/function-[function]/domains/add-domain/+page.svelte

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,21 @@
4848
4949
async function addDomain() {
5050
const apexDomain = getApexDomain(domainName);
51-
let domain = data.domains?.domains.find((d) => d.domain === apexDomain);
51+
let domain = data.domains?.domains.find((d: Models.Domain) => d.domain === apexDomain);
5252
5353
if (apexDomain && !domain && isCloud) {
5454
try {
5555
domain = await sdk.forConsole.domains.create($project.teamId, apexDomain);
5656
} catch (error) {
57-
addNotification({
58-
type: 'error',
59-
message: error.message
60-
});
61-
62-
return;
57+
// apex might already be added on organization level, skip.
58+
const alreadyAdded = error?.type === 'domain_already_exists';
59+
if (!alreadyAdded) {
60+
addNotification({
61+
type: 'error',
62+
message: error.message
63+
});
64+
return;
65+
}
6366
}
6467
}
6568

src/routes/(console)/project-[region]-[project]/settings/domains/add-domain/+page.svelte

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import { isCloud } from '$lib/system';
1313
import { project } from '$routes/(console)/project-[region]-[project]/store';
1414
import { getApexDomain } from '$lib/helpers/tlds';
15+
import type { Models } from '@appwrite.io/console';
1516
1617
const routeBase = `${base}/project-${page.params.region}-${page.params.project}/settings/domains`;
1718
@@ -29,18 +30,21 @@
2930
3031
async function addDomain() {
3132
const apexDomain = getApexDomain(domainName);
32-
let domain = data.domains?.domains.find((d) => d.domain === apexDomain);
33+
let domain = data.domains?.domains.find((d: Models.Domain) => d.domain === apexDomain);
3334
3435
if (apexDomain && !domain && isCloud) {
3536
try {
3637
domain = await sdk.forConsole.domains.create($project.teamId, apexDomain);
3738
} catch (error) {
38-
addNotification({
39-
type: 'error',
40-
message: error.message
41-
});
42-
43-
return;
39+
// apex might already be added on organization level, skip.
40+
const alreadyAdded = error?.type === 'domain_already_exists';
41+
if (!alreadyAdded) {
42+
addNotification({
43+
type: 'error',
44+
message: error.message
45+
});
46+
return;
47+
}
4448
}
4549
}
4650

src/routes/(console)/project-[region]-[project]/sites/site-[site]/domains/add-domain/+page.svelte

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,21 @@
5353
5454
async function addDomain() {
5555
const apexDomain = getApexDomain(domainName);
56-
let domain = data.domains?.domains.find((d) => d.domain === apexDomain);
56+
let domain = data.domains?.domains.find((d: Models.Domain) => d.domain === apexDomain);
5757
5858
if (apexDomain && !domain && isCloud) {
5959
try {
6060
domain = await sdk.forConsole.domains.create($project.teamId, apexDomain);
6161
} catch (error) {
62-
addNotification({
63-
type: 'error',
64-
message: error.message
65-
});
66-
return;
62+
// apex might already be added on organization level, skip.
63+
const alreadyAdded = error?.type === 'domain_already_exists';
64+
if (!alreadyAdded) {
65+
addNotification({
66+
type: 'error',
67+
message: error.message
68+
});
69+
return;
70+
}
6771
}
6872
}
6973

0 commit comments

Comments
 (0)