fix: tighten edge cases across services (#3158)

This commit is contained in:
Hampus authored and GitHub committed 2026-10-03 13:04:29 +02:00
1 parent a9f7a23c0d
commit 4e6b837ccc
170 files changed
+2028 -421

No files matched your search

@@ -89,6 +89,17 @@ describe('AppErrorHandler logging', () => {
expect(details.status).toBe(400);
});
it('logs the matched route pattern instead of the request path', async () => {
const app = createApp();
app.get('/reset/:token', () => {
throw new ServiceUnavailableError({message: 'unavailable'});
});
const response = await app.request('/reset/abc123');
expect(response.status).toBe(503);
expect(logCalls.error).toHaveLength(1);
expect(logCalls.error[0]![0].path).toBe('/reset/:token');
});
it('still reports unexpected errors as unhandled', async () => {
const app = createApp();
app.get('/thing', () => {
@@ -188,7 +188,7 @@ describe('PremiumPurchaseBlockedError', () => {
});
});
it('carries the blocking provider when one is given', () => {
it('includes the blocking provider when one is given', () => {
const error = new PremiumPurchaseBlockedError('existing_subscription', {provider: 'app_store'});
expect(error.toJSON()).toEqual({
@@ -15,6 +15,7 @@ import {
resolveMessageVariables,
} from '@fluxer/errors/src/error_handling/ErrorIntrospection';
import {createJsonErrorResponse} from '@fluxer/errors/src/error_handling/ErrorResponse';
import {resolveRoutePattern} from '@fluxer/errors/src/error_handling/RoutePattern';
import {FluxerError} from '@fluxer/errors/src/FluxerError';
import {ErrorCodeToI18nKey} from '@fluxer/errors/src/i18n/ErrorCodeMappings';
import {getErrorMessageUnsafe} from '@fluxer/errors/src/i18n/ErrorI18n';
@@ -281,7 +282,7 @@ function logErrorResponse<E extends BaseHonoEnv>(err: Error, resolved: ResolvedE
err,
status,
method: ctx.req.method,
path: ctx.req.path,
path: resolveRoutePattern(ctx),
requestId: ctx.get('requestId'),
};
if (resolved.unexpected) {
@@ -0,0 +1,11 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
import type {Context} from 'hono';
import {matchedRoutes} from 'hono/route';
import {METHOD_NAME_ALL} from 'hono/router';
export function resolveRoutePattern(ctx: Context): string {
const routes = matchedRoutes(ctx);
const endpoint = routes.findLast((route) => route.method !== METHOD_NAME_ALL);
return (endpoint ?? routes.at(-1))?.path ?? '*';
}