@kalutskii/foundation 0.2.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +9 -8
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -145,19 +145,20 @@ async function safeExecute(fn, onError) {
|
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
// src/hono/hono.validation.ts
|
|
148
|
+
var FALLBACK_ERROR_MESSAGE = "Failed to read payload";
|
|
148
149
|
var requestReaders = {
|
|
149
|
-
json: async (c) => c.req.json(),
|
|
150
|
+
json: async (c) => safeExecute(() => c.req.json(), () => {
|
|
151
|
+
throw new HTTPException2(400, { message: FALLBACK_ERROR_MESSAGE });
|
|
152
|
+
}),
|
|
150
153
|
query: (c) => c.req.query(),
|
|
151
154
|
param: (c) => c.req.param()
|
|
152
155
|
};
|
|
153
156
|
async function requirePayload(c, target, schema) {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
throw new HTTPException2(400, { message: parsedPayload.error.message });
|
|
160
|
-
});
|
|
157
|
+
const rawPayload = await requestReaders[target](c);
|
|
158
|
+
const parsedPayload = await schema.safeParseAsync(rawPayload);
|
|
159
|
+
if (parsedPayload.success)
|
|
160
|
+
return parsedPayload.data;
|
|
161
|
+
throw new HTTPException2(400, { message: parsedPayload.error.message });
|
|
161
162
|
}
|
|
162
163
|
|
|
163
164
|
// src/utilities/serialization.utilities.ts
|