Compare commits
2 commits
30146556f5
...
c8e4078b35
Author | SHA1 | Date | |
---|---|---|---|
c8e4078b35 | |||
0c6e3bf38f |
12 changed files with 40 additions and 16 deletions
|
@ -58,8 +58,15 @@ public partial class MetaController(Config config) : ApiControllerBase
|
||||||
}
|
}
|
||||||
|
|
||||||
string path = Path.Join(Directory.GetCurrentDirectory(), "static-pages", $"{page}.md");
|
string path = Path.Join(Directory.GetCurrentDirectory(), "static-pages", $"{page}.md");
|
||||||
string text = await System.IO.File.ReadAllTextAsync(path, ct);
|
try
|
||||||
return Ok(text);
|
{
|
||||||
|
string text = await System.IO.File.ReadAllTextAsync(path, ct);
|
||||||
|
return Ok(text);
|
||||||
|
}
|
||||||
|
catch (FileNotFoundException)
|
||||||
|
{
|
||||||
|
throw new ApiError.NotFound("Page not found", code: ErrorCode.PageNotFound);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("/api/v2/coffee")]
|
[HttpGet("/api/v2/coffee")]
|
||||||
|
|
|
@ -164,6 +164,7 @@ public enum ErrorCode
|
||||||
GenericApiError,
|
GenericApiError,
|
||||||
UserNotFound,
|
UserNotFound,
|
||||||
MemberNotFound,
|
MemberNotFound,
|
||||||
|
PageNotFound,
|
||||||
AccountAlreadyLinked,
|
AccountAlreadyLinked,
|
||||||
LastAuthMethod,
|
LastAuthMethod,
|
||||||
InvalidReportTarget,
|
InvalidReportTarget,
|
||||||
|
|
|
@ -21,12 +21,8 @@ Sentry.init({
|
||||||
});
|
});
|
||||||
|
|
||||||
export const handleError: HandleServerError = async ({ error, status, message }) => {
|
export const handleError: HandleServerError = async ({ error, status, message }) => {
|
||||||
// as far as i know, sentry IDs are just UUIDs with the dashes removed. use those here as well
|
|
||||||
let id = crypto.randomUUID().replaceAll("-", "");
|
|
||||||
|
|
||||||
if (error instanceof ApiError) {
|
if (error instanceof ApiError) {
|
||||||
return {
|
return {
|
||||||
error_id: id,
|
|
||||||
status: error.raw?.status || status,
|
status: error.raw?.status || status,
|
||||||
message: error.raw?.message || "Unknown error",
|
message: error.raw?.message || "Unknown error",
|
||||||
code: error.code,
|
code: error.code,
|
||||||
|
@ -34,11 +30,11 @@ export const handleError: HandleServerError = async ({ error, status, message })
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status >= 400 && status <= 499) {
|
if (status >= 400 && status <= 499) {
|
||||||
return { error_id: id, status, message, code: ErrorCode.GenericApiError };
|
return { status, message, code: ErrorCode.GenericApiError };
|
||||||
}
|
}
|
||||||
|
|
||||||
// client errors and backend API errors just clog up sentry, so we don't send those.
|
// client errors and backend API errors just clog up sentry, so we don't send those.
|
||||||
id = Sentry.captureException(error, {
|
const id = Sentry.captureException(error, {
|
||||||
mechanism: {
|
mechanism: {
|
||||||
type: "sveltekit",
|
type: "sveltekit",
|
||||||
handled: false,
|
handled: false,
|
||||||
|
|
|
@ -43,6 +43,7 @@ export enum ErrorCode {
|
||||||
MemberNotFound = "MEMBER_NOT_FOUND",
|
MemberNotFound = "MEMBER_NOT_FOUND",
|
||||||
AccountAlreadyLinked = "ACCOUNT_ALREADY_LINKED",
|
AccountAlreadyLinked = "ACCOUNT_ALREADY_LINKED",
|
||||||
LastAuthMethod = "LAST_AUTH_METHOD",
|
LastAuthMethod = "LAST_AUTH_METHOD",
|
||||||
|
PageNotFound = "PAGE_NOT_FOUND",
|
||||||
// This code isn't actually returned by the API
|
// This code isn't actually returned by the API
|
||||||
Non204Response = "(non 204 response)",
|
Non204Response = "(non 204 response)",
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,8 @@ export default function errorDescription(t: TranslateFn, code: ErrorCode): strin
|
||||||
return t("error.account-already-linked");
|
return t("error.account-already-linked");
|
||||||
case ErrorCode.LastAuthMethod:
|
case ErrorCode.LastAuthMethod:
|
||||||
return t("error.last-auth-method");
|
return t("error.last-auth-method");
|
||||||
|
case ErrorCode.PageNotFound:
|
||||||
|
return t("error.page-not-found");
|
||||||
case ErrorCode.Non204Response:
|
case ErrorCode.Non204Response:
|
||||||
return t("error.generic-error");
|
return t("error.generic-error");
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,7 +120,8 @@
|
||||||
"400-description": "Something went wrong with your request. This error should never land you on this page, so it's probably a bug.",
|
"400-description": "Something went wrong with your request. This error should never land you on this page, so it's probably a bug.",
|
||||||
"500-description": "Something went wrong on the server. Please try again later.",
|
"500-description": "Something went wrong on the server. Please try again later.",
|
||||||
"unknown-status-description": "Something went wrong, but we're not sure what. Please try again.",
|
"unknown-status-description": "Something went wrong, but we're not sure what. Please try again.",
|
||||||
"error-id": "If you report this error to the developers, please give them this ID:"
|
"error-id": "If you report this error to the developers, please give them this ID:",
|
||||||
|
"page-not-found": "No page exists at this URL."
|
||||||
},
|
},
|
||||||
"settings": {
|
"settings": {
|
||||||
"general-information-tab": "General information",
|
"general-information-tab": "General information",
|
||||||
|
@ -321,6 +322,7 @@
|
||||||
"required": "Required"
|
"required": "Required"
|
||||||
},
|
},
|
||||||
"alert": {
|
"alert": {
|
||||||
"auth-method-remove-success": "Successfully unlinked account!"
|
"auth-method-remove-success": "Successfully unlinked account!",
|
||||||
|
"auth-required": "You must log in to access this page."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,5 +19,5 @@ export const load = async ({ url, fetch, cookies }) => {
|
||||||
fetch,
|
fetch,
|
||||||
cookies,
|
cookies,
|
||||||
});
|
});
|
||||||
return { reports, url: url.toString(), byReporter, byTarget, before, after };
|
return { reports, url: url.toString(), includeClosed, byReporter, byTarget, before, after };
|
||||||
};
|
};
|
||||||
|
|
|
@ -18,6 +18,14 @@
|
||||||
return url.toString();
|
return url.toString();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const addClosed = () => {
|
||||||
|
const url = new URL(data.url);
|
||||||
|
if (!data.includeClosed) url.searchParams.set("include-closed", "true");
|
||||||
|
else url.searchParams.delete("include-closed");
|
||||||
|
|
||||||
|
return url.toString();
|
||||||
|
};
|
||||||
|
|
||||||
const addTarget = (id: string | null) => {
|
const addTarget = (id: string | null) => {
|
||||||
const url = new URL(data.url);
|
const url = new URL(data.url);
|
||||||
if (id) url.searchParams.set("by-target", id);
|
if (id) url.searchParams.set("by-target", id);
|
||||||
|
@ -56,6 +64,11 @@
|
||||||
{#if data.byReporter}
|
{#if data.byReporter}
|
||||||
<li>Filtering by reporter (<a href={addReporter(null)}>clear</a>)</li>
|
<li>Filtering by reporter (<a href={addReporter(null)}>clear</a>)</li>
|
||||||
{/if}
|
{/if}
|
||||||
|
{#if data.includeClosed}
|
||||||
|
<li>Showing all reports (<a href={addClosed()}>only show open reports</a>)</li>
|
||||||
|
{:else}
|
||||||
|
<li>Showing open reports (<a href={addClosed()}>show all reports</a>)</li>
|
||||||
|
{/if}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
{#if data.before}
|
{#if data.before}
|
||||||
|
|
|
@ -2,15 +2,15 @@ import { isRedirect, redirect } from "@sveltejs/kit";
|
||||||
|
|
||||||
import { apiRequest } from "$api";
|
import { apiRequest } from "$api";
|
||||||
import type { AuthResponse, AuthUrls } from "$api/models/auth";
|
import type { AuthResponse, AuthUrls } from "$api/models/auth";
|
||||||
import { setToken } from "$lib";
|
import { alertKey, setToken } from "$lib";
|
||||||
import ApiError, { ErrorCode } from "$api/error";
|
import ApiError, { ErrorCode } from "$api/error";
|
||||||
|
|
||||||
export const load = async ({ fetch, parent }) => {
|
export const load = async ({ fetch, parent, url }) => {
|
||||||
const parentData = await parent();
|
const parentData = await parent();
|
||||||
if (parentData.meUser) redirect(303, `/@${parentData.meUser.username}`);
|
if (parentData.meUser) redirect(303, `/@${parentData.meUser.username}`);
|
||||||
|
|
||||||
const urls = await apiRequest<AuthUrls>("POST", "/auth/urls", { fetch, isInternal: true });
|
const urls = await apiRequest<AuthUrls>("POST", "/auth/urls", { fetch, isInternal: true });
|
||||||
return { urls };
|
return { urls, alertKey: alertKey(url) };
|
||||||
};
|
};
|
||||||
|
|
||||||
export const actions = {
|
export const actions = {
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
import { t } from "$lib/i18n";
|
import { t } from "$lib/i18n";
|
||||||
import { enhance } from "$app/forms";
|
import { enhance } from "$app/forms";
|
||||||
import ErrorAlert from "$components/ErrorAlert.svelte";
|
import ErrorAlert from "$components/ErrorAlert.svelte";
|
||||||
|
import UrlAlert from "$components/URLAlert.svelte";
|
||||||
|
|
||||||
type Props = { data: PageData; form: ActionData };
|
type Props = { data: PageData; form: ActionData };
|
||||||
let { data, form }: Props = $props();
|
let { data, form }: Props = $props();
|
||||||
|
@ -13,6 +14,7 @@
|
||||||
</svelte:head>
|
</svelte:head>
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
<UrlAlert {data} />
|
||||||
<div class="row">
|
<div class="row">
|
||||||
{#if form?.error}
|
{#if form?.error}
|
||||||
<ErrorAlert error={form.error} />
|
<ErrorAlert error={form.error} />
|
||||||
|
|
|
@ -2,5 +2,5 @@ import { redirect } from "@sveltejs/kit";
|
||||||
|
|
||||||
export const load = async ({ parent }) => {
|
export const load = async ({ parent }) => {
|
||||||
const { meUser } = await parent();
|
const { meUser } = await parent();
|
||||||
if (!meUser) redirect(303, "/auth/log-in");
|
if (!meUser) redirect(303, "/auth/log-in?alert=auth-required");
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { redirect } from "@sveltejs/kit";
|
||||||
|
|
||||||
export const load = async ({ parent }) => {
|
export const load = async ({ parent }) => {
|
||||||
const data = await parent();
|
const data = await parent();
|
||||||
if (!data.meUser) redirect(303, "/auth/log-in");
|
if (!data.meUser) redirect(303, "/auth/log-in?alert=auth-required");
|
||||||
|
|
||||||
return { user: data.meUser!, token: data.token! };
|
return { user: data.meUser!, token: data.token! };
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue