Resruiin
This commit is contained in:
@@ -45,6 +45,9 @@
|
||||
import { clearBlobUrlCache } from "$lib/cache/mediaCache";
|
||||
import type { Message } from "$lib/matrix/types";
|
||||
import type { SupabaseClient } from "@supabase/supabase-js";
|
||||
import { createLogger, getErrorMessage } from "$lib/utils/logger";
|
||||
|
||||
const log = createLogger('chat:page');
|
||||
|
||||
const supabase = getContext<SupabaseClient>("supabase");
|
||||
let data = $derived(page.data);
|
||||
@@ -120,7 +123,7 @@
|
||||
await initCache();
|
||||
await cleanupCache(7 * 24 * 60 * 60 * 1000);
|
||||
} catch (e) {
|
||||
console.warn("Cache initialization failed:", e);
|
||||
log.warn('Cache initialization failed', { error: e });
|
||||
}
|
||||
|
||||
// Try to load credentials from Supabase
|
||||
@@ -141,7 +144,7 @@
|
||||
isInitializing = false;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("Failed to load Matrix credentials:", e);
|
||||
log.error('Failed to load Matrix credentials', { error: e });
|
||||
showJoinScreen = true;
|
||||
isInitializing = false;
|
||||
}
|
||||
@@ -164,7 +167,7 @@
|
||||
// Check if org has a Matrix Space, auto-create if not
|
||||
await ensureOrgSpace(credentials);
|
||||
} catch (e: unknown) {
|
||||
console.error("Failed to init Matrix client:", e);
|
||||
log.error('Failed to init Matrix client', { error: e });
|
||||
toasts.error(m.chat_join_error());
|
||||
showJoinScreen = true;
|
||||
} finally {
|
||||
@@ -196,7 +199,7 @@
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn("Failed to ensure org space:", e);
|
||||
log.warn('Failed to ensure org space', { error: e });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,8 +226,8 @@
|
||||
if (result.provisioned) {
|
||||
toasts.success(m.chat_join_success());
|
||||
}
|
||||
} catch (e: any) {
|
||||
toasts.error(e.message || m.chat_join_error());
|
||||
} catch (e: unknown) {
|
||||
toasts.error(getErrorMessage(e, m.chat_join_error()));
|
||||
} finally {
|
||||
isProvisioning = false;
|
||||
}
|
||||
@@ -297,8 +300,8 @@
|
||||
await editMessage($selectedRoomId, editingMsg.eventId, newContent);
|
||||
editingMsg = null;
|
||||
toasts.success("Message edited");
|
||||
} catch (e: any) {
|
||||
toasts.error(e.message || "Failed to edit message");
|
||||
} catch (e: unknown) {
|
||||
toasts.error(getErrorMessage(e, 'Failed to edit message'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -312,8 +315,8 @@
|
||||
try {
|
||||
await deleteMessage($selectedRoomId, messageId);
|
||||
toasts.success("Message deleted");
|
||||
} catch (e: any) {
|
||||
toasts.error(e.message || "Failed to delete message");
|
||||
} catch (e: unknown) {
|
||||
toasts.error(getErrorMessage(e, 'Failed to delete message'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -355,8 +358,8 @@
|
||||
const contentUri = await uploadFile(file);
|
||||
await sendFileMessage($selectedRoomId, file, contentUri);
|
||||
toasts.success("File sent!");
|
||||
} catch (e: any) {
|
||||
toasts.error(e.message || "Failed to upload file");
|
||||
} catch (e: unknown) {
|
||||
toasts.error(getErrorMessage(e, 'Failed to upload file'));
|
||||
} finally {
|
||||
isUploadingDrop = false;
|
||||
}
|
||||
@@ -369,8 +372,8 @@
|
||||
const result = await loadMoreMessages($selectedRoomId);
|
||||
loadRoomMessages($selectedRoomId);
|
||||
if (!result.hasMore) toasts.info("No more messages to load");
|
||||
} catch (e: any) {
|
||||
console.error("Failed to load more messages:", e);
|
||||
} catch (e: unknown) {
|
||||
log.error('Failed to load more messages', { error: e });
|
||||
} finally {
|
||||
isLoadingMore = false;
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ export const load: PageServerLoad = async ({ params, locals, url }) => {
|
||||
try {
|
||||
const events = await fetchEvents(locals.supabase, org.id, statusFilter);
|
||||
return { events, statusFilter };
|
||||
} catch (e: any) {
|
||||
} catch (e: unknown) {
|
||||
log.error('Failed to load events', { error: e, data: { orgId: org.id } });
|
||||
return { events: [], statusFilter };
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
import type { SupabaseClient } from "@supabase/supabase-js";
|
||||
import type { Database } from "$lib/supabase/types";
|
||||
import { toasts } from "$lib/stores/ui";
|
||||
import { getErrorMessage } from "$lib/utils/logger";
|
||||
import * as m from "$lib/paraglide/messages";
|
||||
|
||||
interface EventItem {
|
||||
@@ -100,8 +101,8 @@
|
||||
showCreateModal = false;
|
||||
resetForm();
|
||||
goto(`/${data.org.slug}/events/${created.slug}`);
|
||||
} catch (e: any) {
|
||||
toasts.error(e.message || "Failed to create event");
|
||||
} catch (e: unknown) {
|
||||
toasts.error(getErrorMessage(e, 'Failed to create event'));
|
||||
} finally {
|
||||
creating = false;
|
||||
}
|
||||
|
||||
@@ -23,8 +23,8 @@ export const load: LayoutServerLoad = async ({ params, locals, parent }) => {
|
||||
]);
|
||||
|
||||
return { event, eventMembers: members, eventRoles: roles, eventDepartments: departments };
|
||||
} catch (e: any) {
|
||||
if (e?.status === 404) throw e;
|
||||
} catch (e: unknown) {
|
||||
if (e && typeof e === 'object' && 'status' in e && (e as { status: number }).status === 404) throw e;
|
||||
log.error('Failed to load event', { error: e, data: { orgId, eventSlug: params.eventSlug } });
|
||||
error(500, 'Failed to load event');
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
import type { SupabaseClient } from "@supabase/supabase-js";
|
||||
import type { Database } from "$lib/supabase/types";
|
||||
import { toasts } from "$lib/stores/ui";
|
||||
import { getErrorMessage } from "$lib/utils/logger";
|
||||
import type { Event, EventMemberWithDetails, EventRole, EventDepartment } from "$lib/api/events";
|
||||
import * as m from "$lib/paraglide/messages";
|
||||
|
||||
@@ -173,8 +174,8 @@
|
||||
goto(`/${data.org.slug}/events/${data.event.slug}`, {
|
||||
invalidateAll: true,
|
||||
});
|
||||
} catch (e: any) {
|
||||
toasts.error(e.message || "Failed to update event");
|
||||
} catch (e: unknown) {
|
||||
toasts.error(getErrorMessage(e, 'Failed to update event'));
|
||||
} finally {
|
||||
saving = false;
|
||||
}
|
||||
@@ -192,8 +193,8 @@
|
||||
|
||||
toasts.success(m.events_deleted());
|
||||
goto(`/${data.org.slug}/events`);
|
||||
} catch (e: any) {
|
||||
toasts.error(e.message || "Failed to delete event");
|
||||
} catch (e: unknown) {
|
||||
toasts.error(getErrorMessage(e, 'Failed to delete event'));
|
||||
} finally {
|
||||
deleting = false;
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ export const load: PageServerLoad = async ({ params, locals, parent }) => {
|
||||
sponsors,
|
||||
sponsorDeliverables,
|
||||
};
|
||||
} catch (e: any) {
|
||||
} catch (e: unknown) {
|
||||
log.error('Failed to load department dashboard', { error: e, data: { deptId: params.deptId } });
|
||||
error(500, 'Failed to load department dashboard');
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
import type { SupabaseClient } from "@supabase/supabase-js";
|
||||
import type { Database } from "$lib/supabase/types";
|
||||
import { toasts } from "$lib/stores/ui";
|
||||
import { getErrorMessage } from "$lib/utils/logger";
|
||||
import type {
|
||||
Event,
|
||||
EventMemberWithDetails,
|
||||
@@ -260,8 +261,8 @@
|
||||
selectedRoleId = "";
|
||||
selectedDeptIds = [];
|
||||
addNotes = "";
|
||||
} catch (e: any) {
|
||||
toasts.error(e.message || "Failed to add member");
|
||||
} catch (e: unknown) {
|
||||
toasts.error(getErrorMessage(e, 'Failed to add member'));
|
||||
} finally {
|
||||
adding = false;
|
||||
}
|
||||
@@ -327,8 +328,8 @@
|
||||
|
||||
toasts.success(m.team_updated());
|
||||
editingMember = null;
|
||||
} catch (e: any) {
|
||||
toasts.error(e.message || "Failed to update member");
|
||||
} catch (e: unknown) {
|
||||
toasts.error(getErrorMessage(e, 'Failed to update member'));
|
||||
} finally {
|
||||
updatingMember = false;
|
||||
}
|
||||
@@ -349,8 +350,8 @@
|
||||
teamMembers = teamMembers.filter((tm) => tm.id !== memberToRemove!.id);
|
||||
toasts.success(m.team_removed({ name }));
|
||||
memberToRemove = null;
|
||||
} catch (e: any) {
|
||||
toasts.error(e.message || "Failed to remove member");
|
||||
} catch (e: unknown) {
|
||||
toasts.error(getErrorMessage(e, 'Failed to remove member'));
|
||||
} finally {
|
||||
removing = false;
|
||||
}
|
||||
@@ -398,8 +399,8 @@
|
||||
toasts.success(m.team_dept_created());
|
||||
}
|
||||
showDeptModal = false;
|
||||
} catch (e: any) {
|
||||
toasts.error(e.message || "Failed to save department");
|
||||
} catch (e: unknown) {
|
||||
toasts.error(getErrorMessage(e, 'Failed to save department'));
|
||||
} finally {
|
||||
savingDept = false;
|
||||
}
|
||||
@@ -419,8 +420,8 @@
|
||||
departments: tm.departments.filter((d) => d.id !== dept.id),
|
||||
}));
|
||||
toasts.success(m.team_dept_deleted());
|
||||
} catch (e: any) {
|
||||
toasts.error(e.message || "Failed to delete department");
|
||||
} catch (e: unknown) {
|
||||
toasts.error(getErrorMessage(e, 'Failed to delete department'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -464,8 +465,8 @@
|
||||
toasts.success(m.team_role_created());
|
||||
}
|
||||
showRoleModal = false;
|
||||
} catch (e: any) {
|
||||
toasts.error(e.message || "Failed to save role");
|
||||
} catch (e: unknown) {
|
||||
toasts.error(getErrorMessage(e, 'Failed to save role'));
|
||||
} finally {
|
||||
savingRole = false;
|
||||
}
|
||||
@@ -486,8 +487,8 @@
|
||||
: tm,
|
||||
);
|
||||
toasts.success(m.team_role_deleted());
|
||||
} catch (e: any) {
|
||||
toasts.error(e.message || "Failed to delete role");
|
||||
} catch (e: unknown) {
|
||||
toasts.error(getErrorMessage(e, 'Failed to delete role'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -621,8 +621,9 @@
|
||||
<Input label="Name" name="name" bind:value={editEventModal.name} />
|
||||
<Input label="Slug" name="slug" bind:value={editEventModal.slug} />
|
||||
<div>
|
||||
<label class="block text-body-sm text-light/60 mb-1">Status</label>
|
||||
<label for="event-status" class="block text-body-sm text-light/60 mb-1">Status</label>
|
||||
<select
|
||||
id="event-status"
|
||||
name="status"
|
||||
bind:value={editEventModal.status}
|
||||
class="w-full bg-dark/50 border border-light/10 rounded-xl px-3 py-2 text-body-sm text-white focus:outline-none focus:border-primary/50"
|
||||
@@ -634,8 +635,9 @@
|
||||
</div>
|
||||
<div class="grid grid-cols-2 gap-3">
|
||||
<div>
|
||||
<label class="block text-body-sm text-light/60 mb-1">Start Date</label>
|
||||
<label for="event-start-date" class="block text-body-sm text-light/60 mb-1">Start Date</label>
|
||||
<input
|
||||
id="event-start-date"
|
||||
type="date"
|
||||
name="start_date"
|
||||
bind:value={editEventModal.start_date}
|
||||
@@ -643,8 +645,9 @@
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-body-sm text-light/60 mb-1">End Date</label>
|
||||
<label for="event-end-date" class="block text-body-sm text-light/60 mb-1">End Date</label>
|
||||
<input
|
||||
id="event-end-date"
|
||||
type="date"
|
||||
name="end_date"
|
||||
bind:value={editEventModal.end_date}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import { json } from '@sveltejs/kit';
|
||||
import { env } from '$env/dynamic/private';
|
||||
import type { RequestHandler } from './$types';
|
||||
import { createLogger } from '$lib/utils/logger';
|
||||
|
||||
const log = createLogger('api:matrix-provision');
|
||||
|
||||
/**
|
||||
* POST /api/matrix-provision
|
||||
@@ -83,7 +86,7 @@ export const POST: RequestHandler = async ({ request, locals }) => {
|
||||
|
||||
if (!registerRes.ok) {
|
||||
const err = await registerRes.json().catch(() => ({}));
|
||||
console.error('Matrix register failed:', registerRes.status, err);
|
||||
log.error('Matrix register failed', { data: { status: registerRes.status }, error: err });
|
||||
return json({ error: 'Failed to create Matrix account' }, { status: 500 });
|
||||
}
|
||||
|
||||
@@ -104,7 +107,7 @@ export const POST: RequestHandler = async ({ request, locals }) => {
|
||||
|
||||
if (!loginRes.ok) {
|
||||
const err = await loginRes.json().catch(() => ({}));
|
||||
console.error('Matrix login failed:', loginRes.status, err);
|
||||
log.error('Matrix login failed', { data: { status: loginRes.status }, error: err });
|
||||
return json({ error: 'Failed to login to Matrix account' }, { status: 500 });
|
||||
}
|
||||
|
||||
@@ -118,7 +121,7 @@ export const POST: RequestHandler = async ({ request, locals }) => {
|
||||
try {
|
||||
await setMatrixAvatar(homeserverUrl, accessToken, profile.avatar_url);
|
||||
} catch (e) {
|
||||
console.warn('Failed to set Matrix avatar:', e);
|
||||
log.warn('Failed to set Matrix avatar', { error: e });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,7 +141,7 @@ export const POST: RequestHandler = async ({ request, locals }) => {
|
||||
);
|
||||
|
||||
if (upsertError) {
|
||||
console.error('Failed to store Matrix credentials:', upsertError);
|
||||
log.error('Failed to store Matrix credentials', { error: upsertError });
|
||||
return json({ error: 'Failed to store credentials' }, { status: 500 });
|
||||
}
|
||||
|
||||
@@ -152,7 +155,7 @@ export const POST: RequestHandler = async ({ request, locals }) => {
|
||||
provisioned: true,
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('Matrix provisioning error:', e);
|
||||
log.error('Matrix provisioning error', { error: e });
|
||||
return json({ error: 'Matrix provisioning failed' }, { status: 500 });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import { json } from '@sveltejs/kit';
|
||||
import type { RequestHandler } from './$types';
|
||||
import { createLogger, getErrorMessage } from '$lib/utils/logger';
|
||||
|
||||
const log = createLogger('api:matrix-space');
|
||||
|
||||
/**
|
||||
* GET: Retrieve the Matrix Space ID for an org
|
||||
@@ -140,9 +143,9 @@ export const POST: RequestHandler = async ({ request, locals }) => {
|
||||
}
|
||||
|
||||
return json({ spaceId, created: true });
|
||||
} catch (e: any) {
|
||||
console.error('Failed to create Matrix Space:', e);
|
||||
return json({ error: e.message || 'Failed to create Matrix Space' }, { status: 500 });
|
||||
} catch (e: unknown) {
|
||||
log.error('Failed to create Matrix Space', { error: e });
|
||||
return json({ error: getErrorMessage(e, 'Failed to create Matrix Space') }, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user