Skip to content

Commit

Permalink
🚨 Update error messages and suppress ts error
Browse files Browse the repository at this point in the history
Using URLSearchParams(form_data) doesn't gel well with TS.
See microsoft/TypeScript#30584
  • Loading branch information
tameTNT committed Aug 11, 2023
1 parent b1189f7 commit 89f9458
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/app/login-test/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@ import { FormEvent } from "react";
async function send_login_request(event: FormEvent<HTMLFormElement>) {
event.preventDefault();
const form_data = new FormData(event.currentTarget);
// @ts-ignore (see https://github.com/microsoft/TypeScript/issues/30584)
const encoded_form_data = new URLSearchParams(form_data);
const request = makeMegateamsApiRequest("/auth/login", { method: "POST", body: encoded_form_data });
await attachCsrfTokenToRequest(request);
await fetch(request);
}

async function send_set_password_request(event) {
async function send_set_password_request(event: FormEvent<HTMLFormElement>) {
event.preventDefault();
const form_data = new FormData(event.currentTarget);
// @ts-ignore (same as above)
const encoded_form_data = new URLSearchParams(form_data);
const request = makeMegateamsApiRequest("/auth/setpassword", { method: "POST", body: encoded_form_data });
await attachCsrfTokenToRequest(request);
Expand Down
4 changes: 2 additions & 2 deletions src/server/database/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ export function buildQueryFromRequest<M extends Model>(request: Request, transfo
const parameterValue = request.query[parameterName];

if (typeof parameterValue !== "string") {
throw new createHttpError.BadRequest(`query parameter '${parameterName}' should contain a single string.`);
throw new createHttpError.BadRequest(`Query parameter '${parameterName}' should be a string.`);
}

const transformFactory = transforms.get(parameterName);
if (transformFactory === undefined) {
throw new createHttpError.BadRequest(`Invalid query parameter '${parameterName}'`);
throw new createHttpError.BadRequest(`Query parameter '${parameterName}' is invalid.`);
}

const transform = transformFactory(parameterValue);
Expand Down

0 comments on commit 89f9458

Please sign in to comment.