Skip to content

Commit

Permalink
feat(resolvers): add async error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
TomokiMiyauci committed Oct 14, 2022
1 parent 5e867a9 commit 9571d26
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,13 @@ export function validate(data: json): Result<
export async function resolvePostParams(
request: Request,
): Promise<Result<RawParams, HttpError>> {
const text = await request.text();
const result = unsafe<json, TypeError>(() => JSON.parse(text));
const textResult = await request.text().then(Result.ok).catch(Result.err);

if (isErr(textResult)) {
return Result.err(createHttpError(Status.BadRequest));
}

const result = unsafe<json, TypeError>(() => JSON.parse(textResult.value));

if (isErr(result)) {
return Result.err(
Expand Down

0 comments on commit 9571d26

Please sign in to comment.