Validate timezone with normalizeZone
Instead of constructing a new DateTime object and seeing if it
succeeded, validate the client's timezone selection using the
Info.normalizeZone utility function. This prevents throwing an
unexpected error creating the DateTime object after the change
in e100555
to throw on invalid dates.
This commit is contained in:
parent
bb450fd583
commit
f4f23e6c18
1 changed files with 4 additions and 4 deletions
|
@ -1,5 +1,5 @@
|
||||||
import { readAccounts, writeAccounts } from "~/server/database";
|
import { readAccounts, writeAccounts } from "~/server/database";
|
||||||
import { DateTime } from "luxon";
|
import { DateTime, Info } from "~/shared/utils/luxon";
|
||||||
import { apiAccountPatchSchema } from "~/shared/types/api";
|
import { apiAccountPatchSchema } from "~/shared/types/api";
|
||||||
import { z } from "zod/v4-mini";
|
import { z } from "zod/v4-mini";
|
||||||
|
|
||||||
|
@ -16,11 +16,11 @@ export default defineEventHandler(async (event) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (patch.timezone?.length) {
|
if (patch.timezone?.length) {
|
||||||
const zonedTime = DateTime.local({ locale: "en-US" }).setZone(patch.timezone);
|
const zone = Info.normalizeZone(patch.timezone);
|
||||||
if (!zonedTime.isValid) {
|
if (!zone.isValid) {
|
||||||
throw createError({
|
throw createError({
|
||||||
status: 400,
|
status: 400,
|
||||||
message: "Invalid timezone: " + zonedTime.invalidExplanation,
|
message: `Invalid timezone: the zone "${patch.timezone} is not supported`,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue