Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit ae843c7

Browse files
committed
feat: added try/block catch
1 parent 4bb7e31 commit ae843c7

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

api.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,15 @@ export class Request extends ServerRequest implements APIRequest {
8585
}
8686

8787
async jsonBody(): Promise<any> {
88-
const buff: Uint8Array = await Deno.readAll(this.body);
89-
const encoded = new TextDecoder("utf-8").decode(buff);
90-
const json = JSON.parse(encoded);
91-
return json;
88+
try {
89+
const buff: Uint8Array = await Deno.readAll(this.body);
90+
const encoded = new TextDecoder("utf-8").decode(buff);
91+
const json = JSON.parse(encoded);
92+
return json;
93+
} catch (err) {
94+
console.error("Failed to parse the request body.", err);
95+
return null;
96+
}
9297
}
9398

9499
async send(data: string | Uint8Array | ArrayBuffer, contentType?: string): Promise<void> {

0 commit comments

Comments
 (0)