diff --git a/envoy/envoy.yaml b/envoy/envoy.yaml index f3e6a1f..4b85404 100644 --- a/envoy/envoy.yaml +++ b/envoy/envoy.yaml @@ -26,10 +26,14 @@ static_resources: prefix: application/grpc route: cluster: grpc_backend + timeout: 60s + max_stream_duration: + max_stream_duration: 300s - match: prefix: "/" route: cluster: http_backend + timeout: 60s http_filters: - name: envoy.filters.http.router typed_config: diff --git a/src/interceptors/auth.ts b/src/interceptors/auth.ts index 13135eb..076b955 100644 --- a/src/interceptors/auth.ts +++ b/src/interceptors/auth.ts @@ -243,13 +243,21 @@ export function authInterceptor( } return handler(call, callback); }) - .catch((error) => callback?.(error)); + .catch((error) => { + return callback?.({ + code: grpcStatus.UNAVAILABLE, + details: error instanceof Error ? error.message : String(error), + }); + }); } return handler(call, callback); }) .catch((error) => { - return callback?.(error); + return callback?.({ + code: grpcStatus.UNAVAILABLE, + details: error instanceof Error ? error.message : String(error), + }); }); }; } diff --git a/src/interceptors/logging.ts b/src/interceptors/logging.ts index bfb5495..b9321f2 100644 --- a/src/interceptors/logging.ts +++ b/src/interceptors/logging.ts @@ -1,5 +1,5 @@ import { status as grpcStatus } from "@grpc/grpc-js"; -import type { sendUnaryData, ServerErrorResponse } from "@grpc/grpc-js"; +import type { sendUnaryData } from "@grpc/grpc-js"; import * as Sentry from "@sentry/bun"; import { logger } from "../errors/logger"; import { @@ -72,10 +72,10 @@ export function loggingInterceptor( // Handle async handlers that might throw if (result && typeof result.then === "function") { return result.catch((error: unknown) => { - if (!builder["event"].outcome) { - const errorDetails = extractErrorDetails(error); - const statusCode = grpcStatusToHttpStatus(errorDetails.code); + const errorDetails = extractErrorDetails(error); + const statusCode = grpcStatusToHttpStatus(errorDetails.code); + if (!builder["event"].outcome) { Sentry.captureException(error, { extra: { requestId, method: url, statusCode }, }); @@ -89,7 +89,11 @@ export function loggingInterceptor( const event = builder.build(); logger.emit(event); } - throw error; + + originalCallback?.({ + code: errorDetails.code, + details: errorDetails.message, + }); }); } };