hono-problem-details 0.12.0 → 0.12.1

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/README.md CHANGED
@@ -539,14 +539,19 @@ problemDetailsHandler({
539
539
 
540
540
  The callback receives the fully-built `ProblemDetails` object and the Hono `Context`, allowing access to headers like `Accept-Language`. Return a new `ProblemDetails` with translated fields.
541
541
 
542
+ > **Note on extensions**: The patch is merged shallowly, so returning `extensions` replaces
543
+ > all extension members (`code`, `traceId`, validation `errors`, ...). Spread the original
544
+ > to keep them: `return { extensions: { ...pd.extensions, hint: translate(lang, "hint") } }`.
545
+
542
546
  > **Note on caching**: If your responses vary by `Accept-Language`, add `Vary: Accept-Language`
543
547
  > from your own middleware so CDNs and browser caches don't serve the wrong translation.
544
548
  > This middleware intentionally does not set `Vary` — error handlers shouldn't mutate
545
549
  > request-scope headers that also apply to successful responses.
546
550
 
547
551
  > **Note on failures**: If your `localize` callback throws, the handler falls back to the
548
- > un-localized `ProblemDetails` and continues. Throwing from inside `app.onError` would cause
549
- > the error handler to re-enter itself, so the swallow is deliberate. Catch errors inside your
552
+ > un-localized `ProblemDetails` and continues. Hono hands an error thrown from inside
553
+ > `app.onError` back to `onError` (several times when middleware is present), and if it keeps
554
+ > throwing, the request rejects, so the swallow is deliberate. Catch errors inside your
550
555
  > callback if you need to observe them.
551
556
 
552
557
  ## OpenTelemetry Integration
package/dist/index.cjs CHANGED
@@ -233,7 +233,7 @@ function toResponse(input, c, options) {
233
233
  return buildProblemResponse(pd);
234
234
  }
235
235
  function problemDetailsHandler(options = {}) {
236
- return (error, c) => {
236
+ const handle = (error, c) => {
237
237
  if (error instanceof ProblemDetailsError) {
238
238
  const pd = error.problemDetails;
239
239
  return toResponse(error.hasExplicitType ? pd : { ...pd, type: void 0 }, c, options);
@@ -278,6 +278,12 @@ function problemDetailsHandler(options = {}) {
278
278
  options
279
279
  );
280
280
  };
281
+ const dispatch = (first, second) => {
282
+ if (typeof second !== "function") return handle(first, second);
283
+ const c = first;
284
+ return c.error ? handle(c.error, c) : second();
285
+ };
286
+ return dispatch;
281
287
  }
282
288
 
283
289
  // src/registry.ts
package/dist/index.d.cts CHANGED
@@ -75,6 +75,9 @@ interface ProblemDetailsHandlerOptions {
75
75
  * Localize title/detail before sending the response.
76
76
  * Returned fields are merged onto the original ProblemDetails, so callers may
77
77
  * return a partial patch (e.g. `{ title: "..." }`) or omit the return entirely.
78
+ * The merge is shallow: a returned `extensions` replaces all extension members,
79
+ * so spread `pd.extensions` to keep `code`, `traceId`, or validation `errors`.
80
+ * A throwing callback is swallowed and the un-localized response is sent (ADR-0003).
78
81
  */
79
82
  localize?: (pd: ProblemDetails, c: Context) => Partial<ProblemDetails> | undefined;
80
83
  /**
package/dist/index.d.ts CHANGED
@@ -75,6 +75,9 @@ interface ProblemDetailsHandlerOptions {
75
75
  * Localize title/detail before sending the response.
76
76
  * Returned fields are merged onto the original ProblemDetails, so callers may
77
77
  * return a partial patch (e.g. `{ title: "..." }`) or omit the return entirely.
78
+ * The merge is shallow: a returned `extensions` replaces all extension members,
79
+ * so spread `pd.extensions` to keep `code`, `traceId`, or validation `errors`.
80
+ * A throwing callback is swallowed and the un-localized response is sent (ADR-0003).
78
81
  */
79
82
  localize?: (pd: ProblemDetails, c: Context) => Partial<ProblemDetails> | undefined;
80
83
  /**
package/dist/index.js CHANGED
@@ -82,7 +82,7 @@ function toResponse(input, c, options) {
82
82
  return buildProblemResponse(pd);
83
83
  }
84
84
  function problemDetailsHandler(options = {}) {
85
- return (error, c) => {
85
+ const handle = (error, c) => {
86
86
  if (error instanceof ProblemDetailsError) {
87
87
  const pd = error.problemDetails;
88
88
  return toResponse(error.hasExplicitType ? pd : { ...pd, type: void 0 }, c, options);
@@ -127,6 +127,12 @@ function problemDetailsHandler(options = {}) {
127
127
  options
128
128
  );
129
129
  };
130
+ const dispatch = (first, second) => {
131
+ if (typeof second !== "function") return handle(first, second);
132
+ const c = first;
133
+ return c.error ? handle(c.error, c) : second();
134
+ };
135
+ return dispatch;
130
136
  }
131
137
 
132
138
  // src/registry.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hono-problem-details",
3
- "version": "0.12.0",
3
+ "version": "0.12.1",
4
4
  "description": "RFC 9457 Problem Details middleware for Hono",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -151,22 +151,22 @@
151
151
  "devDependencies": {
152
152
  "@arethetypeswrong/cli": "0.18.5",
153
153
  "@biomejs/biome": "^2.4.14",
154
- "@changesets/changelog-github": "0.7.0",
155
- "@changesets/cli": "2.31.1",
154
+ "@changesets/changelog-github": "1.0.1",
155
+ "@changesets/cli": "3.0.3",
156
156
  "@hono/standard-validator": "0.4.0",
157
157
  "@hono/valibot-validator": "^0.6.1",
158
158
  "@hono/zod-openapi": "1.6.3",
159
159
  "@hono/zod-validator": "^0.9.0",
160
160
  "@opentelemetry/api": "^1.0.0",
161
161
  "@standard-schema/spec": "1.1.0",
162
- "@vitest/coverage-v8": "^4.1.8",
162
+ "@vitest/coverage-v8": "^4.1.12",
163
163
  "hono": "^4.13.7",
164
- "knip": "6.38.0",
165
- "lefthook": "2.1.14",
164
+ "knip": "6.41.0",
165
+ "lefthook": "2.2.1",
166
166
  "tsup": "^8.0.0",
167
167
  "typescript": "^6.0.3",
168
168
  "valibot": "^1.3.1",
169
- "vitest": "^4.1.8",
169
+ "vitest": "^4.1.12",
170
170
  "zod": "^4.0.0"
171
171
  },
172
172
  "engines": {