fix: handle missing deploymentId gracefully

This commit is contained in:
Harsh Mahajan
2025-11-21 05:38:50 +00:00
parent 81c53a49ab
commit f1d40aefef
3 changed files with 41 additions and 17 deletions
@@ -15,17 +15,27 @@ export const load: PageLoad = async ({ params, depends, url, route, parent }) =>
const parsedQueries = queryParamToMap(query || '[]');
queries.set(parsedQueries);
let activeDeployment = null;
if (data.function.deploymentId) {
try {
activeDeployment = await sdk
.forProject(params.region, params.project)
.functions.getDeployment({
functionId: params.function,
deploymentId: data.function.deploymentId
});
} catch (error) {
// active deployment with the requested ID could not be found
activeDeployment = null;
}
}
return {
offset,
limit,
query,
installations: data.installations,
activeDeployment: data.function.deploymentId
? await sdk.forProject(params.region, params.project).functions.getDeployment({
functionId: params.function,
deploymentId: data.function.deploymentId
})
: null,
activeDeployment,
deploymentList: await sdk
.forProject(params.region, params.project)
.functions.listDeployments({
@@ -46,11 +46,18 @@ export const load = async ({ params, depends, parent }) => {
})
]);
const deployment = deploymentList?.total
? await sdk
.forProject(params.region, params.project)
.sites.getDeployment({ siteId: params.site, deploymentId: site.deploymentId })
: null;
let deployment = null;
if (deploymentList?.total && site.deploymentId) {
try {
deployment = await sdk
.forProject(params.region, params.project)
.sites.getDeployment({ siteId: params.site, deploymentId: site.deploymentId });
} catch (error) {
// active deployment with the requested ID could not be found
deployment = null;
}
}
return {
site,
deploymentList,
@@ -37,17 +37,24 @@ export const load = async ({ params, depends, url, route, parent }) => {
sdk.forProject(params.region, params.project).vcs.listInstallations()
]);
let activeDeployment = null;
if (site.deploymentId && deploymentList?.total) {
try {
activeDeployment = await sdk
.forProject(params.region, params.project)
.sites.getDeployment({ siteId: params.site, deploymentId: site.deploymentId });
} catch (error) {
// active deployment with the requested ID could not be found
activeDeployment = null;
}
}
return {
offset,
limit,
query,
deploymentList,
activeDeployment:
site.deploymentId && deploymentList?.total
? await sdk
.forProject(params.region, params.project)
.sites.getDeployment({ siteId: params.site, deploymentId: site.deploymentId })
: null,
activeDeployment,
installations
};
};