Skip to content

Commit

Permalink
Catch error
Browse files Browse the repository at this point in the history
  • Loading branch information
timonson committed May 21, 2024
1 parent d288748 commit 2fda553
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions server/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,25 +93,29 @@ export function respondByHandlingFormData(
return async (request: Request): Promise<Response> => {
const headers = options.headers ?? new Headers();
if (request.headers.get("content-type")?.includes("multipart/form-data")) {
const formData = await request.formData();
const rpcRequestString = formData.get("rpc")?.toString();
if (rpcRequestString) {
const newRequest = createNewRpcRequest(request, rpcRequestString);
const blobs: Record<string, Blob> = {};
formData.forEach((value, key) => {
if (key !== "rpc") {
blobs[key] = value as Blob;
}
});
const updatedOptions = {
...options,
acceptFormData: false,
args: { ...options.args, blobs },
};
return await respond(methods, updatedOptions, authInput)(
newRequest,
);
} else {
try {
const formData = await request.formData();
const rpcRequestString = formData.get("rpc")?.toString();
if (rpcRequestString) {
const newRequest = createNewRpcRequest(request, rpcRequestString);
const blobs: Record<string, Blob> = {};
formData.forEach((value, key) => {
if (key !== "rpc") {
blobs[key] = value as Blob;
}
});
const updatedOptions = {
...options,
acceptFormData: false,
args: { ...options.args, blobs },
};
return await respond(methods, updatedOptions, authInput)(
newRequest,
);
} else {
throw new Error();
}
} catch {
headers.append("content-type", "application/json");
return new Response(
JSON.stringify({
Expand Down

0 comments on commit 2fda553

Please sign in to comment.