Skip to content

Commit 8c5129f

Browse files
committed
error handling
1 parent dca376c commit 8c5129f

File tree

6 files changed

+79
-105
lines changed

6 files changed

+79
-105
lines changed

src/global.d.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
11
/// <reference types="@sveltejs/kit" />
2-
interface Window {}
2+
interface Window { }
3+
4+
namespace App {
5+
interface Error {
6+
type: string,
7+
resource: ?string = '',
8+
}
9+
}
Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
<script>
22
import { page } from '$app/state';
33
import { Container } from '$lib/layout';
4-
import { Typography } from '@appwrite.io/pink-svelte';
4+
import { Card, Typography } from '@appwrite.io/pink-svelte';
55
</script>
66

77
<Container>
8-
<Typography.Title size="xl"
9-
>{'status' in page.error
10-
? page.error.status || 'Invalid Argument'
11-
: 'Invalid Argument'}</Typography.Title>
12-
<p class="body-text-2 u-bold u-margin-block-start-4">{page.error.message}</p>
8+
{#if page.error.type === 'general_resource_blocked'}
9+
{@const resource = page.error.resource || 'project'}
10+
<Card.Base>
11+
<Typography.Title size="s">Your {resource} is paused</Typography.Title>
12+
<p class="text-red-500">
13+
We've detected unusual activity and temporarily paused your {resource}. If you
14+
believe this is a mistake or need urgent access, please contact [email protected].
15+
</p>
16+
</Card.Base>
17+
{:else}
18+
<Typography.Title size="xl"
19+
>{'status' in page.error
20+
? page.error.status || 'Invalid Argument'
21+
: 'Invalid Argument'}</Typography.Title>
22+
<p class="body-text-2 u-bold u-margin-block-start-4">{page.error.message}</p>
23+
{/if}
1324
</Container>

src/routes/(console)/project-[region]-[project]/databases/+page.svelte

Lines changed: 47 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
import { Icon, Layout } from '@appwrite.io/pink-svelte';
1818
import { IconPlus } from '@appwrite.io/pink-icons-svelte';
1919
import EmptySearch from '$lib/components/emptySearch.svelte';
20-
import ErrorResourceBlocked from '../errorResourceBlocked.svelte';
21-
import ErrorFailedToLoad from '../errorFailedToLoad.svelte';
2220
2321
export let data: PageData;
2422
@@ -48,64 +46,56 @@
4846
]);
4947
</script>
5048

51-
{#if data.error}
52-
{#if data.error.type === 'general_resource_blocked'}
53-
<ErrorResourceBlocked resource="Databases" />
54-
{:else}
55-
<ErrorFailedToLoad resource="Databases" />
56-
{/if}
57-
{:else}
58-
<Container>
59-
<Layout.Stack direction="row" justifyContent="space-between">
60-
<Layout.Stack direction="row" alignItems="center">
61-
<SearchQuery placeholder="Search by name or ID" />
62-
</Layout.Stack>
63-
<Layout.Stack direction="row" alignItems="center" justifyContent="flex-end">
64-
<ViewSelector
65-
{columns}
66-
view={data.view}
67-
hideColumns={!data.databases.total}
68-
hideView={!data.databases.total} />
69-
{#if $canWriteDatabases}
70-
<Button
71-
on:click={() => (showCreate = true)}
72-
event="create_database"
73-
disabled={isCreationDisabled}>
74-
<Icon icon={IconPlus} slot="start" size="s" />
75-
Create database
76-
</Button>
77-
{/if}
78-
</Layout.Stack>
49+
<Container>
50+
<Layout.Stack direction="row" justifyContent="space-between">
51+
<Layout.Stack direction="row" alignItems="center">
52+
<SearchQuery placeholder="Search by name or ID" />
7953
</Layout.Stack>
80-
81-
{#if data.databases.total}
82-
{#if data.view === 'grid'}
83-
<Grid {data} bind:showCreate />
84-
{:else}
85-
<Table {data} />
54+
<Layout.Stack direction="row" alignItems="center" justifyContent="flex-end">
55+
<ViewSelector
56+
{columns}
57+
view={data.view}
58+
hideColumns={!data.databases.total}
59+
hideView={!data.databases.total} />
60+
{#if $canWriteDatabases}
61+
<Button
62+
on:click={() => (showCreate = true)}
63+
event="create_database"
64+
disabled={isCreationDisabled}>
65+
<Icon icon={IconPlus} slot="start" size="s" />
66+
Create database
67+
</Button>
8668
{/if}
69+
</Layout.Stack>
70+
</Layout.Stack>
8771

88-
<PaginationWithLimit
89-
name="Databases"
90-
limit={data.limit}
91-
offset={data.offset}
92-
total={data.databases.total} />
93-
{:else if data.search}
94-
<EmptySearch target="databases" hidePagination>
95-
<Button
96-
href={`${base}/project-${page.params.region}-${page.params.project}/databases`}
97-
size="s"
98-
secondary>Clear Search</Button>
99-
</EmptySearch>
72+
{#if data.databases.total}
73+
{#if data.view === 'grid'}
74+
<Grid {data} bind:showCreate />
10075
{:else}
101-
<Empty
102-
single
103-
href="https://appwrite.io/docs/products/databases/databases"
104-
target="database"
105-
allowCreate={$canWriteDatabases}
106-
on:click={() => (showCreate = true)} />
76+
<Table {data} />
10777
{/if}
108-
</Container>
10978

110-
<Create bind:showCreate on:created={handleCreate} />
111-
{/if}
79+
<PaginationWithLimit
80+
name="Databases"
81+
limit={data.limit}
82+
offset={data.offset}
83+
total={data.databases.total} />
84+
{:else if data.search}
85+
<EmptySearch target="databases" hidePagination>
86+
<Button
87+
href={`${base}/project-${page.params.region}-${page.params.project}/databases`}
88+
size="s"
89+
secondary>Clear Search</Button>
90+
</EmptySearch>
91+
{:else}
92+
<Empty
93+
single
94+
href="https://appwrite.io/docs/products/databases/databases"
95+
target="database"
96+
allowCreate={$canWriteDatabases}
97+
on:click={() => (showCreate = true)} />
98+
{/if}
99+
</Container>
100+
101+
<Create bind:showCreate on:created={handleCreate} />

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

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type { BackupPolicy } from '$lib/sdk/backups';
88
import { isSelfHosted } from '$lib/system';
99
import { isCloud } from '$lib/system';
1010
import type { Plan } from '$lib/sdk/billing';
11+
import { error } from '@sveltejs/kit';
1112

1213
export const load: PageLoad = async ({ url, route, depends, params, parent }) => {
1314
depends(Dependencies.DATABASES);
@@ -39,16 +40,12 @@ export const load: PageLoad = async ({ url, route, depends, params, parent }) =>
3940
lastBackups
4041
};
4142

42-
} catch (error) {
43-
return {
44-
error: {
45-
type: error.type,
46-
},
47-
offset,
48-
limit,
49-
view,
50-
search,
51-
};
43+
} catch (e) {
44+
error(e.status || 500, {
45+
message: e.message,
46+
type: e.type || 'unknown',
47+
resource: 'databases'
48+
});
5249
}
5350
};
5451

src/routes/(console)/project-[region]-[project]/errorFailedToLoad.svelte

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/routes/(console)/project-[region]-[project]/errorResourceBlocked.svelte

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)