Skip to content

Commit

Permalink
fix: SyntaxErrorがログに記録される問題の修正
Browse files Browse the repository at this point in the history
レコーディングの削除処理のなかでレスポンスが空で得られるエンドポイントへのリクエストがあり、そこで呼ばれる Response.json() メソッドからパース時に SyntaxError が出力される問題がありました。レコーディングの削除処理については Response.json() メソッドを呼ばない fetcher を使用するように変更しこの問題を解決します。
  • Loading branch information
kou029w committed Oct 17, 2023
1 parent f7940b2 commit b63d70e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
18 changes: 17 additions & 1 deletion server/utils/zoom/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
ZOOM_CLIENT_SECRET,
} from "$server/utils/env";
import { fetch } from "undici";
import { type Request, jsonFetcher } from "./fetcher";
import { type Request, jsonFetcher, fetcher } from "./fetcher";

/**
* List users
Expand Down Expand Up @@ -377,6 +377,22 @@ export async function zoomRequest<ZoomResponse extends Record<string, unknown>>(
});
}

/** JSONのパースを行わないリクエスト */
export async function zoomRequestWithoutParse(
path: string,
searchParams: Request["searchParams"] = {},
method: Request["method"] = "GET"
): Promise<void> {
const access_token = await zoomRequestToken();

await fetcher({
url: `https://api.zoom.us/v2${path}`,
token: access_token,
searchParams,
method,
});
}

export async function zoomListRequest<
ZoomListResponse extends Array<Record<string, unknown>>,
>(
Expand Down
2 changes: 1 addition & 1 deletion server/utils/zoom/fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export type Request = {
* @param req リクエスト
* @returns Response
*/
async function fetcher(req: Request): Promise<Response> {
export async function fetcher(req: Request): Promise<Response> {
const url = req.url
.concat(`?${new URLSearchParams(req.searchParams)}`)
.replace(/\?$/, "");
Expand Down
3 changes: 2 additions & 1 deletion server/utils/zoom/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import type {
import {
zoomRequestToken,
zoomRequest,
zoomRequestWithoutParse,
zoomListRequest,
} from "$server/utils/zoom/api";
import { logger } from "$server/utils/zoom/env";
Expand Down Expand Up @@ -139,7 +140,7 @@ class ZoomImport {
if (!ZOOM_IMPORT_DISABLE_AUTOPUBLIC)
await prisma.$transaction(this.getPublicBooks(results));
for (const deletemeeting of deletemeetings) {
await zoomRequest(
await zoomRequestWithoutParse(
`/meetings/${deletemeeting}/recordings`,
{ action: "trash" },
"DELETE"
Expand Down

0 comments on commit b63d70e

Please sign in to comment.