mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-18 13:35:42 +09:00
fix(api): reject unparsable bodies and screen non-form ones (#2503)
This commit is contained in:
1 parent
f8a04b8985
commit
f06d65db54
5 files changed
+72
-3
No files matched your search
@@ -1,5 +1,7 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import {ValidationErrorCodes} from '@fluxer/constants/src/ValidationErrorCodes';
|
||||
import {InputValidationError} from '@fluxer/errors/src/domains/core/InputValidationError';
|
||||
import type {HonoRequest} from 'hono';
|
||||
import {parseJsonPreservingLargeIntegers} from './LosslessJsonParser';
|
||||
|
||||
@@ -24,3 +26,11 @@ export async function readRequestJsonBody(req: HonoRequest): Promise<RequestJson
|
||||
bodyCache.set(raw, body);
|
||||
return body;
|
||||
}
|
||||
|
||||
export async function requireRequestJsonBody(req: HonoRequest): Promise<unknown> {
|
||||
const body = await readRequestJsonBody(req);
|
||||
if (!body.parsed) {
|
||||
throw InputValidationError.fromCode('body', ValidationErrorCodes.INVALID_FORMAT);
|
||||
}
|
||||
return body.value;
|
||||
}
|
||||
Reference in new issue
Block a user