@jon49/sw 0.14.5 → 0.14.6

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.
@@ -138,12 +138,25 @@ async function executeHandler({ url, req, ctx }: ExectuteHandlerOptions): Promis
138
138
  const data = await getData(req)
139
139
  let query = searchParams<{ handler?: string }>(url)
140
140
  let args = { req, data, query }
141
- let result = await (
142
- handlers instanceof Function
143
- ? handlers(args)
144
- : (call(handlers[query.handler ?? ""], args)
145
- || call(handlers[method], args)
146
- || Promise.reject("I'm sorry, I didn't understand where to route your request.")))
141
+ let result
142
+ try {
143
+ result = await (
144
+ handlers instanceof Function
145
+ ? handlers(args)
146
+ : (call(handlers[query.handler ?? ""], args)
147
+ || call(handlers[method], args)
148
+ || Promise.reject("I'm sorry, I didn't understand where to route your request.")))
149
+ } catch (e: any) {
150
+ if (e.reasons) {
151
+ ctx.messages =
152
+ e.reasons.map((x: any) => x.reason.reasons).flat().map((x: any) => x.reason).flat()
153
+ return {
154
+ status: 204,
155
+ }
156
+ } else {
157
+ throw e
158
+ }
159
+ }
147
160
 
148
161
  if (!result) {
149
162
  return isPost
@@ -309,4 +322,4 @@ type RequireAtLeastOne<T, Keys extends keyof T = keyof T> =
309
322
  }[Keys]
310
323
 
311
324
  export type Route = RequireAtLeastOne<Route_, "file" | "get" | "post">
312
- export type RoutePage = Pick<Route_, "get" | "post">
325
+ export type RoutePage = Pick<Route_, "get" | "post">
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jon49/sw",
3
- "version": "0.14.5",
3
+ "version": "0.14.6",
4
4
  "description": "Packages for MVC service workers.",
5
5
  "type": "module",
6
6
  "files": [