cloudflare-next-intl 0.8.19 → 0.8.20

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.
@@ -115,6 +115,29 @@ export default async function connectToPostgres(config, resolved) {
115
115
  connectionString = resolved ?? await resolveConnectionString(db);
116
116
  const { Client } = await import('pg');
117
117
  const created = serializeQueries(new Client({ connectionString }));
118
+ // The shared client outlives a single request (see the module doc)
119
+ // and Hyperdrive/Postgres can close its idle socket at any time. `pg`
120
+ // surfaces that as an `'error'` event on the `Client`, which is an
121
+ // `EventEmitter` — with no listener, Node treats it as unhandled and
122
+ // throws, crashing whatever unrelated request happens to be running
123
+ // in the isolate at that moment. Listening here converts it into a
124
+ // clean reset so the next call reconnects instead.
125
+ created.on('error', (error) => {
126
+ if (client === created) {
127
+ client = null;
128
+ connectionString = null;
129
+ connectionPromise = null;
130
+ }
131
+ // `pg` emits "Connection terminated"/"Connection terminated
132
+ // unexpectedly" (lib/client.js) — never "Connection closed" —
133
+ // when the idle socket dies outside a query. That's the
134
+ // expected shape of this event (Hyperdrive/Postgres recycling
135
+ // the connection, not a query failure): swallow it entirely,
136
+ // don't report or log it.
137
+ if (/connection terminated/i.test(error.message))
138
+ return;
139
+ void reportError({ errorHandling: config.errorHandling, generate: config.generate }, { error, classOrMethodName: 'db.connectToPostgres.clientError' });
140
+ });
118
141
  client = created;
119
142
  await created.connect();
120
143
  return created;
@@ -34,7 +34,8 @@ import { type ReportErrorConfig } from './report_error';
34
34
  * `config.errorHandling.ignoreConsoleErrors` (default
35
35
  * `defaultIgnoredConsoleErrors` — this package's own Firebase Auth error
36
36
  * codes for expected user-input failures) and `ignoreConsoleError` both
37
- * skip reporting a matching call while still logging it normally.
37
+ * skip reporting a matching call while still logging it normally — checked
38
+ * inside `reportError` itself, so this override doesn't duplicate the check.
38
39
  *
39
40
  * @param config Pass the relevant slices of your `RoutingConfig` directly —
40
41
  * `{ errorHandling: config.errorHandling, generate: config.generate }`.
@@ -1,6 +1,4 @@
1
1
  import reportError, { consoleOverrideState } from './report_error';
2
- import stringifyUnknown from './stringify_unknown';
3
- import { defaultIgnoredConsoleErrors } from './default_ignored_console_errors';
4
2
  /**
5
3
  * Replaces the global `console.error` so every `console.error(...)` call is
6
4
  * also routed through `config.errorHandling.onError`/`reportError` — the
@@ -36,7 +34,8 @@ import { defaultIgnoredConsoleErrors } from './default_ignored_console_errors';
36
34
  * `config.errorHandling.ignoreConsoleErrors` (default
37
35
  * `defaultIgnoredConsoleErrors` — this package's own Firebase Auth error
38
36
  * codes for expected user-input failures) and `ignoreConsoleError` both
39
- * skip reporting a matching call while still logging it normally.
37
+ * skip reporting a matching call while still logging it normally — checked
38
+ * inside `reportError` itself, so this override doesn't duplicate the check.
40
39
  *
41
40
  * @param config Pass the relevant slices of your `RoutingConfig` directly —
42
41
  * `{ errorHandling: config.errorHandling, generate: config.generate }`.
@@ -58,12 +57,6 @@ export default function installConsoleErrorOverride(config, isClient) {
58
57
  if (!suppressOnClient) {
59
58
  originalConsoleError(message, ...optionalParams);
60
59
  }
61
- const stringified = stringifyUnknown(message, isClient);
62
- const ignoreList = config.errorHandling?.ignoreConsoleErrors ?? defaultIgnoredConsoleErrors;
63
- if (ignoreList.some((ignored) => stringified.includes(ignored)))
64
- return;
65
- if (config.errorHandling?.ignoreConsoleError?.(stringified))
66
- return;
67
60
  void reportError(config, { error: message, classOrMethodName: 'Global Console Error Handler', params: optionalParams, isClient });
68
61
  };
69
62
  override.__isErrorHandlingOverride = true;
@@ -1,5 +1,6 @@
1
1
  import formatErrorMessage from './format_error_message';
2
2
  import stringifyUnknown from './stringify_unknown';
3
+ import { defaultIgnoredConsoleErrors } from './default_ignored_console_errors';
3
4
  const DEFAULT_THROTTLE_MS = 5000;
4
5
  // Set by `installConsoleErrorOverride` once it patches `console.error`.
5
6
  // When active, THAT override is the sole place that ever calls the real
@@ -105,6 +106,18 @@ export default async function reportError(config, params) {
105
106
  return;
106
107
  if (params.consent !== undefined && params.consent !== true)
107
108
  return;
109
+ // `ignoreConsoleErrors`/`ignoreConsoleError` used to only be consulted by
110
+ // `installConsoleErrorOverride`'s patched `console.error` — any direct
111
+ // `reportError`/`reportClientError` call (a caught DB/query error, an
112
+ // error boundary's `reportClientError(error, ...)`, etc.) skipped this
113
+ // check entirely and always reached `onError`. Checking it here instead
114
+ // makes every path share the one ignore list.
115
+ const stringified = stringifyUnknown(params.error, params.isClient);
116
+ const ignoreList = errorHandling?.ignoreConsoleErrors ?? defaultIgnoredConsoleErrors;
117
+ if (ignoreList.some((ignored) => stringified.includes(ignored)))
118
+ return;
119
+ if (errorHandling?.ignoreConsoleError?.(stringified))
120
+ return;
108
121
  if (errorHandling?.dedup !== false) {
109
122
  const throttleMs = errorHandling?.throttleMs ?? DEFAULT_THROTTLE_MS;
110
123
  const dedupKey = buildDedupKey(params);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cloudflare-next-intl",
3
- "version": "0.8.19",
3
+ "version": "0.8.20",
4
4
  "description": "Optimized Next Intl Package Special for App Router and Cloudflare",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",