Skip to content

Commit ac85bfc

Browse files
committed
handle blocks in other project routes
1 parent 8c5129f commit ac85bfc

File tree

5 files changed

+113
-59
lines changed

5 files changed

+113
-59
lines changed

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

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,31 @@ import { sdk } from '$lib/stores/sdk';
44
import { Query } from '@appwrite.io/console';
55
import { Dependencies } from '$lib/constants';
66
import type { LayoutLoad } from './$types';
7+
import { error } from '@sveltejs/kit';
78

89
export const load: LayoutLoad = async ({ depends, params }) => {
910
depends(Dependencies.FUNCTION_INSTALLATIONS);
1011

11-
const [runtimesList, installations, specificationsList] = await Promise.all([
12-
sdk.forProject(params.region, params.project).functions.listRuntimes(),
13-
sdk.forProject(params.region, params.project).vcs.listInstallations([Query.limit(100)]),
14-
sdk.forProject(params.region, params.project).functions.listSpecifications()
15-
]);
12+
try {
1613

17-
return {
18-
header: Header,
19-
breadcrumbs: Breadcrumbs,
20-
runtimesList,
21-
installations,
22-
specificationsList
23-
};
14+
const [runtimesList, installations, specificationsList] = await Promise.all([
15+
sdk.forProject(params.region, params.project).functions.listRuntimes(),
16+
sdk.forProject(params.region, params.project).vcs.listInstallations([Query.limit(100)]),
17+
sdk.forProject(params.region, params.project).functions.listSpecifications()
18+
]);
19+
20+
return {
21+
header: Header,
22+
breadcrumbs: Breadcrumbs,
23+
runtimesList,
24+
installations,
25+
specificationsList
26+
};
27+
} catch (e) {
28+
error(e.code || 500, {
29+
message: e.message,
30+
type: e.type || 'unknown',
31+
resource: 'functions'
32+
});
33+
}
2434
};

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

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
import { sdk } from '$lib/stores/sdk';
1313
import { Query, type Models } from '@appwrite.io/console';
1414
import type { PageLoad } from './$types';
15+
import { error } from '@sveltejs/kit';
1516

1617
export const load: PageLoad = async ({ depends, url, route, params }) => {
1718
depends(Dependencies.MESSAGING_MESSAGES);
@@ -26,14 +27,8 @@ export const load: PageLoad = async ({ depends, url, route, params }) => {
2627
const parsedQueries = queryParamToMap(query || '[]');
2728
queries.set(parsedQueries);
2829

29-
return {
30-
offset,
31-
limit,
32-
search,
33-
query,
34-
page,
35-
view,
36-
messages: (await sdk
30+
try {
31+
const messages = (await sdk
3732
.forProject(params.region, params.project)
3833
.messaging.listMessages(
3934
[
@@ -44,8 +39,27 @@ export const load: PageLoad = async ({ depends, url, route, params }) => {
4439
],
4540
search || undefined
4641
)) as {
47-
total: number;
48-
messages: (Models.Message & { data: Record<string, string> })[]; // Add typing for message.data
49-
}
50-
};
42+
total: number;
43+
messages: (Models.Message & { data: Record<string, string> })[]; // Add typing for message.data
44+
};
45+
46+
return {
47+
messages,
48+
offset,
49+
limit,
50+
search,
51+
query,
52+
page,
53+
view,
54+
};
55+
} catch (e) {
56+
return error(
57+
e.code || 500,
58+
{
59+
message: e.message,
60+
type: e.type || 'unknown',
61+
resource: 'messaging'
62+
}
63+
)
64+
}
5165
};

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

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,33 @@ import { Dependencies, PAGE_LIMIT } from '$lib/constants';
22
import { sdk } from '$lib/stores/sdk';
33
import { Query } from '@appwrite.io/console';
44
import type { PageLoad } from './$types';
5+
import { error } from '@sveltejs/kit';
56

67
export const load: PageLoad = async ({ depends, url, params }) => {
78
depends(Dependencies.PROJECT_VARIABLES);
89
depends(Dependencies.PROJECT_INSTALLATIONS);
910
const limit = PAGE_LIMIT;
1011
const offset = Number(url.searchParams.get('offset') ?? 0);
1112

12-
const [variables, installations] = await Promise.all([
13-
sdk.forProject(params.region, params.project).projectApi.listVariables(),
14-
sdk
15-
.forProject(params.region, params.project)
16-
.vcs.listInstallations([Query.limit(limit), Query.offset(offset)])
17-
]);
13+
try {
14+
const [variables, installations] = await Promise.all([
15+
sdk.forProject(params.region, params.project).projectApi.listVariables(),
16+
sdk
17+
.forProject(params.region, params.project)
18+
.vcs.listInstallations([Query.limit(limit), Query.offset(offset)])
19+
]);
1820

19-
return {
20-
limit,
21-
offset,
22-
variables,
23-
installations
24-
};
21+
return {
22+
limit,
23+
offset,
24+
variables,
25+
installations
26+
};
27+
} catch (e) {
28+
error(e.code || 500, {
29+
message: e.message,
30+
type: e.type || 'unknown',
31+
resource: 'project'
32+
});
33+
}
2534
};

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

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Query, type Models } from '@appwrite.io/console';
22
import { sdk } from '$lib/stores/sdk';
33
import { getLimit, getPage, getSearch, getView, pageToOffset, View } from '$lib/helpers/load';
44
import { CARD_LIMIT, Dependencies } from '$lib/constants';
5+
import { error } from '@sveltejs/kit';
56

67
export const load = async ({ url, depends, route, params }) => {
78
depends(Dependencies.SITES);
@@ -26,19 +27,28 @@ export const load = async ({ url, depends, route, params }) => {
2627
} as Models.SiteList
2728
};
2829

29-
const siteList = await sdk
30-
.forProject(params.region, params.project)
31-
.sites.list(
32-
[Query.limit(limit), Query.offset(offset), Query.orderDesc('')],
33-
search || undefined
34-
);
30+
try {
31+
const siteList = await sdk
32+
.forProject(params.region, params.project)
33+
.sites.list(
34+
[Query.limit(limit), Query.offset(offset), Query.orderDesc('')],
35+
search || undefined
36+
);
3537

36-
return {
37-
sitesLive,
38-
offset,
39-
limit,
40-
search,
41-
siteList,
42-
view
43-
};
38+
return {
39+
sitesLive,
40+
offset,
41+
limit,
42+
search,
43+
siteList,
44+
view
45+
};
46+
} catch (e) {
47+
error(e.code || 500,
48+
{
49+
message: e.message,
50+
type: e.type || 'unknown',
51+
resource: 'sites'
52+
});
53+
}
4454
};

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

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,35 @@ import { sdk } from '$lib/stores/sdk';
33
import { getLimit, getPage, getSearch, getView, pageToOffset, View } from '$lib/helpers/load';
44
import { CARD_LIMIT } from '$lib/constants';
55
import type { PageLoad } from './$types';
6+
import { error } from '@sveltejs/kit';
67

78
export const load: PageLoad = async ({ url, route, params }) => {
89
const page = getPage(url);
910
const search = getSearch(url);
1011
const view = getView(url, route, View.Grid);
1112
const limit = getLimit(url, route, CARD_LIMIT);
1213
const offset = pageToOffset(page, limit);
13-
14-
return {
15-
offset,
16-
limit,
17-
view,
18-
search,
19-
buckets: await sdk
14+
try {
15+
const buckets = await sdk
2016
.forProject(params.region, params.project)
2117
.storage.listBuckets(
2218
[Query.limit(limit), Query.offset(offset), Query.orderDesc('')],
2319
search || undefined
24-
)
25-
};
20+
);
21+
22+
return {
23+
offset,
24+
limit,
25+
view,
26+
search,
27+
buckets,
28+
};
29+
} catch (e) {
30+
error(e.code || 500, {
31+
message: e.message,
32+
type: e.type || 'unknown',
33+
resource: 'storage'
34+
}
35+
);
36+
}
2637
};

0 commit comments

Comments
 (0)