Skip to content

Commit 553587e

Browse files
authored
Merge pull request #2626 from appwrite/fix-SER-635-handle-missing-deployment-id
2 parents 81c53a4 + 667cc6c commit 553587e

3 files changed

Lines changed: 44 additions & 20 deletions

File tree

  • src/routes/(console)/project-[region]-[project]

src/routes/(console)/project-[region]-[project]/functions/function-[function]/+page.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Query } from '@appwrite.io/console';
1+
import { Query, type Models } from '@appwrite.io/console';
22
import { sdk } from '$lib/stores/sdk';
33
import { getLimit, getPage, getQuery, pageToOffset } from '$lib/helpers/load';
44
import { Dependencies, PAGE_LIMIT } from '$lib/constants';
@@ -15,17 +15,27 @@ export const load: PageLoad = async ({ params, depends, url, route, parent }) =>
1515

1616
const parsedQueries = queryParamToMap(query || '[]');
1717
queries.set(parsedQueries);
18+
let activeDeployment: Models.Deployment | null = null;
19+
if (data.function.deploymentId) {
20+
try {
21+
activeDeployment = await sdk
22+
.forProject(params.region, params.project)
23+
.functions.getDeployment({
24+
functionId: params.function,
25+
deploymentId: data.function.deploymentId
26+
});
27+
} catch (error) {
28+
// active deployment with the requested ID could not be found
29+
activeDeployment = null;
30+
}
31+
}
32+
1833
return {
1934
offset,
2035
limit,
2136
query,
2237
installations: data.installations,
23-
activeDeployment: data.function.deploymentId
24-
? await sdk.forProject(params.region, params.project).functions.getDeployment({
25-
functionId: params.function,
26-
deploymentId: data.function.deploymentId
27-
})
28-
: null,
38+
activeDeployment,
2939
deploymentList: await sdk
3040
.forProject(params.region, params.project)
3141
.functions.listDeployments({

src/routes/(console)/project-[region]-[project]/sites/site-[site]/+page.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { sdk } from '$lib/stores/sdk';
22
import { Dependencies } from '$lib/constants';
3-
import { Query } from '@appwrite.io/console';
3+
import { Query, type Models } from '@appwrite.io/console';
44
import { RuleType } from '$lib/stores/sdk';
55
import { DeploymentResourceType } from '$lib/stores/sdk';
66

@@ -46,11 +46,18 @@ export const load = async ({ params, depends, parent }) => {
4646
})
4747
]);
4848

49-
const deployment = deploymentList?.total
50-
? await sdk
51-
.forProject(params.region, params.project)
52-
.sites.getDeployment({ siteId: params.site, deploymentId: site.deploymentId })
53-
: null;
49+
let deployment: Models.Deployment | null = null;
50+
if (deploymentList?.total && site.deploymentId) {
51+
try {
52+
deployment = await sdk
53+
.forProject(params.region, params.project)
54+
.sites.getDeployment({ siteId: params.site, deploymentId: site.deploymentId });
55+
} catch (error) {
56+
// active deployment with the requested ID could not be found
57+
deployment = null;
58+
}
59+
}
60+
5461
return {
5562
site,
5663
deploymentList,

src/routes/(console)/project-[region]-[project]/sites/site-[site]/deployments/+page.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Query } from '@appwrite.io/console';
1+
import { Query, type Models } from '@appwrite.io/console';
22
import { sdk } from '$lib/stores/sdk';
33
import { getLimit, getPage, getQuery, pageToOffset } from '$lib/helpers/load';
44
import { Dependencies, PAGE_LIMIT } from '$lib/constants';
@@ -37,17 +37,24 @@ export const load = async ({ params, depends, url, route, parent }) => {
3737
sdk.forProject(params.region, params.project).vcs.listInstallations()
3838
]);
3939

40+
let activeDeployment: Models.Deployment | null = null;
41+
if (site.deploymentId && deploymentList?.total) {
42+
try {
43+
activeDeployment = await sdk
44+
.forProject(params.region, params.project)
45+
.sites.getDeployment({ siteId: params.site, deploymentId: site.deploymentId });
46+
} catch (error) {
47+
// active deployment with the requested ID could not be found
48+
activeDeployment = null;
49+
}
50+
}
51+
4052
return {
4153
offset,
4254
limit,
4355
query,
4456
deploymentList,
45-
activeDeployment:
46-
site.deploymentId && deploymentList?.total
47-
? await sdk
48-
.forProject(params.region, params.project)
49-
.sites.getDeployment({ siteId: params.site, deploymentId: site.deploymentId })
50-
: null,
57+
activeDeployment,
5158
installations
5259
};
5360
};

0 commit comments

Comments
 (0)