@kalutskii/foundation 0.2.1 → 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.
Files changed (2) hide show
  1. package/dist/index.js +8 -10
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -147,20 +147,18 @@ async function safeExecute(fn, onError) {
147
147
  // src/hono/hono.validation.ts
148
148
  var FALLBACK_ERROR_MESSAGE = "Failed to read payload";
149
149
  var requestReaders = {
150
- json: async (c) => c.req.json(),
150
+ json: async (c) => safeExecute(() => c.req.json(), () => {
151
+ throw new HTTPException2(400, { message: FALLBACK_ERROR_MESSAGE });
152
+ }),
151
153
  query: (c) => c.req.query(),
152
154
  param: (c) => c.req.param()
153
155
  };
154
156
  async function requirePayload(c, target, schema) {
155
- return safeExecute(async () => {
156
- const rawPayload = await requestReaders[target](c);
157
- const parsedPayload = await schema.safeParseAsync(rawPayload);
158
- if (parsedPayload.success)
159
- return parsedPayload.data;
160
- throw new HTTPException2(400, { message: parsedPayload.error.message });
161
- }, () => {
162
- throw new HTTPException2(400, { message: FALLBACK_ERROR_MESSAGE });
163
- });
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 });
164
162
  }
165
163
 
166
164
  // src/utilities/serialization.utilities.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kalutskii/foundation",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "Typescript collection of most common utilities, schemas and functions among private projects.",
5
5
  "type": "module",
6
6
  "repository": {