mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-09-11 05:36:10 -05:00
Change invariant to validate with good error message
This commit is contained in:
@@ -82,7 +82,11 @@ export const action: ActionFunction = async ({ request, params }) => {
|
||||
const eventId = idFromParams(params);
|
||||
const event = notFoundIfFalsy(findByIdentifier(eventId));
|
||||
|
||||
invariant(event.isBeforeStart);
|
||||
validate(
|
||||
event.isBeforeStart,
|
||||
400,
|
||||
"Tournament has started, cannot make edits to registration"
|
||||
);
|
||||
|
||||
const teams = findTeamsByEventId(eventId);
|
||||
const ownTeam = teams.find((team) =>
|
||||
|
||||
@@ -94,10 +94,14 @@ function formDataToObject(formData: FormData) {
|
||||
|
||||
/** Asserts condition is truthy. Throws a new `Response` with given status code if falsy. */
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- same format as TS docs: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#assertion-functions
|
||||
export function validate(condition: any, status = 400): asserts condition {
|
||||
export function validate(
|
||||
condition: any,
|
||||
status = 400,
|
||||
body?: string
|
||||
): asserts condition {
|
||||
if (condition) return;
|
||||
|
||||
throw new Response(null, { status });
|
||||
throw new Response(body, { status });
|
||||
}
|
||||
|
||||
export type Breadcrumb =
|
||||
|
||||
Reference in New Issue
Block a user