Unified · Split
| @@ -1,21 +1,30 @@ | ||
| 1 | 1 | import { createClerkClient, verifyToken } from "@clerk/backend"; |
| 2 | 2 | import { describe, expect, it } from "@effect/vitest"; |
| 3 | 3 | import { vi } from "vite-plus/test"; |
| 4 | +import * as Cause from "effect/Cause"; | |
| 4 | 5 | import * as Context from "effect/Context"; |
| 5 | 6 | import * as Effect from "effect/Effect"; |
| 6 | 7 | import * as Layer from "effect/Layer"; |
| 8 | +import * as Logger from "effect/Logger"; | |
| 7 | 9 | import * as Option from "effect/Option"; |
| 8 | 10 | import * as Predicate from "effect/Predicate"; |
| 9 | 11 | import * as Redacted from "effect/Redacted"; |
| 12 | +import * as References from "effect/References"; | |
| 10 | 13 | import * as Tracer from "effect/Tracer"; |
| 11 | 14 | import * as HttpRouter from "effect/unstable/http/HttpRouter"; |
| 12 | 15 | import * as HttpServerRequest from "effect/unstable/http/HttpServerRequest"; |
| 13 | 16 | import * as HttpServerResponse from "effect/unstable/http/HttpServerResponse"; |
| 14 | −import { RelayEnvironmentAuth } from "@t3tools/contracts/relay"; | |
| 17 | +import { | |
| 18 | + RelayEnvironmentAuth, | |
| 19 | + RelayEnvironmentConnectNotAuthorizedError, | |
| 20 | + RelayInternalError, | |
| 21 | +} from "@t3tools/contracts/relay"; | |
| 15 | 22 | |
| 16 | 23 | import { |
| 17 | 24 | ClerkBearerTokenVerificationError, |
| 18 | 25 | ClerkTokenVerificationError, |
| 26 | + mapErrorTags, | |
| 27 | + mapRelayCommonApiErrors, | |
| 19 | 28 | relayCors, |
| 20 | 29 | relayDocsRedirectRoute, |
| 21 | 30 | relayEnvironmentAuthLayer, |
| @@ -27,6 +36,7 @@ import { · 5 unmodified lines | ||
| 27 | 36 | } from "./Api.ts"; |
| 28 | 37 | import * as RelayConfiguration from "../Config.ts"; |
| 29 | 38 | import * as EnvironmentCredentials from "../environments/EnvironmentCredentials.ts"; |
| 39 | +import * as EnvironmentConnector from "../environments/EnvironmentConnector.ts"; | |
| 30 | 40 | |
| 31 | 41 | vi.mock("@clerk/backend", () => ({ |
| 32 | 42 | createClerkClient: vi.fn(), |
| @@ -52,6 +62,19 @@ const relaySettings: RelayConfiguration.RelayConfiguration["Service"] = { · 19 unmodified lines | ||
| 52 | 62 | managedEndpointNamespace: undefined, |
| 53 | 63 | }; |
| 54 | 64 | |
| 65 | +const projectionTraceId = "00000000000000000000000000000042"; | |
| 66 | +const projectionParentSpan = Tracer.externalSpan({ | |
| 67 | + traceId: projectionTraceId, | |
| 68 | + spanId: "0000000000000042", | |
| 69 | + sampled: true, | |
| 70 | +}); | |
| 71 | + | |
| 72 | +interface CapturedLog { | |
| 73 | + readonly message: unknown; | |
| 74 | + readonly cause: Cause.Cause<unknown>; | |
| 75 | + readonly annotations: Readonly<Record<string, unknown>>; | |
| 76 | +} | |
| 77 | + | |
| 55 | 78 | describe("relay client authentication", () => { |
| 56 | 79 | it.effect("preserves the existing Clerk session JWT path", () => |
| 57 | 80 | Effect.gen(function* () { |
| @@ -242,6 +265,14 @@ describe("relay DPoP token exchange authentication", () => { · 184 unmodified lines | ||
| 242 | 265 | |
| 243 | 266 | describe("relay environment authentication", () => { |
| 244 | 267 | it.effect("preserves credential lookup persistence failures as internal errors", () => { |
| 268 | + const logs: CapturedLog[] = []; | |
| 269 | + const logger = Logger.make(({ cause, fiber, message }) => { | |
| 270 | + logs.push({ | |
| 271 | + message, | |
| 272 | + cause, | |
| 273 | + annotations: fiber.getRef(References.CurrentLogAnnotations), | |
| 274 | + }); | |
| 275 | + }); | |
| 245 | 276 | const failure = new EnvironmentCredentials.EnvironmentCredentialAuthenticatePersistenceError({ |
| 246 | 277 | stage: "lookup-credential", |
| 247 | 278 | cause: "database unavailable", |
| @@ -265,8 +296,25 @@ describe("relay environment authentication", () => { · 17 unmodified lines | ||
| 265 | 296 | expect(Predicate.isTagged(error, "RelayInternalError")).toBe(true); |
| 266 | 297 | if (Predicate.isTagged(error, "RelayInternalError")) { |
| 267 | 298 | expect(error.reason).toBe("persistence_failed"); |
| 299 | + expect(error.traceId).toBe(projectionTraceId); | |
| 300 | + expect(error).not.toHaveProperty("cause"); | |
| 268 | 301 | } |
| 302 | + expect(logs).toEqual([ | |
| 303 | + { | |
| 304 | + message: ["relay API failure projected to wire response"], | |
| 305 | + cause: Cause.fail(failure), | |
| 306 | + annotations: expect.objectContaining({ | |
| 307 | + traceId: projectionTraceId, | |
| 308 | + sourceErrorTag: "EnvironmentCredentialAuthenticatePersistenceError", | |
| 309 | + responseErrorTag: "RelayInternalError", | |
| 310 | + responseCode: "internal_error", | |
| 311 | + responseReason: "persistence_failed", | |
| 312 | + }), | |
| 313 | + }, | |
| 314 | + ]); | |
| 269 | 315 | }).pipe( |
| 316 | + Effect.provideService(Tracer.ParentSpan, projectionParentSpan), | |
| 317 | + Effect.provide(Logger.layer([logger], { mergeWithExisting: false })), | |
| 270 | 318 | Effect.provideService( |
| 271 | 319 | HttpServerRequest.HttpServerRequest, |
| 272 | 320 | HttpServerRequest.fromWeb(new Request("https://relay.test/v1/server/link")), |
| @@ -286,6 +334,128 @@ describe("relay environment authentication", () => { · 13 unmodified lines | ||
| 286 | 334 | }); |
| 287 | 335 | }); |
| 288 | 336 | |
| 337 | +describe("relay API error projection", () => { | |
| 338 | + it.effect("logs common persistence failures with the wire response trace", () => { | |
| 339 | + const logs: CapturedLog[] = []; | |
| 340 | + const logger = Logger.make(({ cause, fiber, message }) => { | |
| 341 | + logs.push({ | |
| 342 | + message, | |
| 343 | + cause, | |
| 344 | + annotations: fiber.getRef(References.CurrentLogAnnotations), | |
| 345 | + }); | |
| 346 | + }); | |
| 347 | + const databaseCause = new Error("database connection refused"); | |
| 348 | + const failure = new EnvironmentCredentials.EnvironmentCredentialRevokePersistenceError({ | |
| 349 | + environmentId: "env-test", | |
| 350 | + cause: databaseCause, | |
| 351 | + }); | |
| 352 | + | |
| 353 | + return Effect.gen(function* () { | |
| 354 | + const error = yield* Effect.fail(failure).pipe( | |
| 355 | + mapRelayCommonApiErrors("not_authorized"), | |
| 356 | + Effect.flip, | |
| 357 | + ); | |
| 358 | + | |
| 359 | + expect(error).toBeInstanceOf(RelayInternalError); | |
| 360 | + expect(error).toMatchObject({ | |
| 361 | + code: "internal_error", | |
| 362 | + reason: "persistence_failed", | |
| 363 | + traceId: projectionTraceId, | |
| 364 | + }); | |
| 365 | + expect(error).not.toHaveProperty("cause"); | |
| 366 | + expect(logs).toEqual([ | |
| 367 | + { | |
| 368 | + message: ["relay API failure projected to wire response"], | |
| 369 | + cause: Cause.fail(failure), | |
| 370 | + annotations: expect.objectContaining({ | |
| 371 | + traceId: projectionTraceId, | |
| 372 | + sourceErrorTag: "EnvironmentCredentialRevokePersistenceError", | |
| 373 | + responseErrorTag: "RelayInternalError", | |
| 374 | + responseCode: "internal_error", | |
| 375 | + responseReason: "persistence_failed", | |
| 376 | + }), | |
| 377 | + }, | |
| 378 | + ]); | |
| 379 | + expect(failure.cause).toBe(databaseCause); | |
| 380 | + }).pipe( | |
| 381 | + Effect.provideService(Tracer.ParentSpan, projectionParentSpan), | |
| 382 | + Effect.provide(Logger.layer([logger], { mergeWithExisting: false })), | |
| 383 | + ); | |
| 384 | + }); | |
| 385 | + | |
| 386 | + it.effect("logs selected server failures but not expected authorization projections", () => { | |
| 387 | + const logs: CapturedLog[] = []; | |
| 388 | + const logger = Logger.make(({ cause, fiber, message }) => { | |
| 389 | + logs.push({ | |
| 390 | + message, | |
| 391 | + cause, | |
| 392 | + annotations: fiber.getRef(References.CurrentLogAnnotations), | |
| 393 | + }); | |
| 394 | + }); | |
| 395 | + const serverCause = new Error("mint request transport failed"); | |
| 396 | + const serverFailure = EnvironmentConnector.EnvironmentMintRequestFailed.fromEndpoint({ | |
| 397 | + userId: "user-test", | |
| 398 | + environmentId: "env-test", | |
| 399 | + operation: "connect", | |
| 400 | + stage: "send_request", | |
| 401 | + httpBaseUrl: "https://environment.example.test", | |
| 402 | + cause: serverCause, | |
| 403 | + }); | |
| 404 | + const authorizationFailure = new EnvironmentConnector.EnvironmentConnectNotAuthorized({ | |
| 405 | + environmentId: "env-test", | |
| 406 | + operation: "connect", | |
| 407 | + reason: "environment_link_not_found", | |
| 408 | + }); | |
| 409 | + | |
| 410 | + return Effect.gen(function* () { | |
| 411 | + const serverError = yield* Effect.fail(serverFailure).pipe( | |
| 412 | + mapErrorTags({ | |
| 413 | + EnvironmentMintRequestFailed: (_error, traceId) => | |
| 414 | + new RelayInternalError({ | |
| 415 | + code: "internal_error", | |
| 416 | + reason: "upstream_unavailable", | |
| 417 | + traceId, | |
| 418 | + }), | |
| 419 | + }), | |
| 420 | + Effect.flip, | |
| 421 | + ); | |
| 422 | + const authorizationError = yield* Effect.fail(authorizationFailure).pipe( | |
| 423 | + mapErrorTags({ | |
| 424 | + EnvironmentConnectNotAuthorized: (_error, traceId) => | |
| 425 | + new RelayEnvironmentConnectNotAuthorizedError({ | |
| 426 | + code: "environment_connect_not_authorized", | |
| 427 | + traceId, | |
| 428 | + }), | |
| 429 | + }), | |
| 430 | + Effect.flip, | |
| 431 | + ); | |
| 432 | + | |
| 433 | + expect(serverError).toMatchObject({ | |
| 434 | + reason: "upstream_unavailable", | |
| 435 | + traceId: projectionTraceId, | |
| 436 | + }); | |
| 437 | + expect(authorizationError.traceId).toBe(projectionTraceId); | |
| 438 | + expect(logs).toEqual([ | |
| 439 | + { | |
| 440 | + message: ["relay API failure projected to wire response"], | |
| 441 | + cause: Cause.fail(serverFailure), | |
| 442 | + annotations: expect.objectContaining({ | |
| 443 | + traceId: projectionTraceId, | |
| 444 | + sourceErrorTag: "EnvironmentMintRequestFailed", | |
| 445 | + responseErrorTag: "RelayInternalError", | |
| 446 | + responseCode: "internal_error", | |
| 447 | + responseReason: "upstream_unavailable", | |
| 448 | + }), | |
| 449 | + }, | |
| 450 | + ]); | |
| 451 | + expect(serverFailure.cause).toBe(serverCause); | |
| 452 | + }).pipe( | |
| 453 | + Effect.provideService(Tracer.ParentSpan, projectionParentSpan), | |
| 454 | + Effect.provide(Logger.layer([logger], { mergeWithExisting: false })), | |
| 455 | + ); | |
| 456 | + }); | |
| 457 | +}); | |
| 458 | + | |
| 289 | 459 | describe("relay request tracing", () => { |
| 290 | 460 | it.effect( |
| 291 | 461 | "does not parent endpoint spans to an ambient parent captured while building handlers", |
| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | import { createClerkClient, verifyToken } from "@clerk/backend"; |
| 2 | 2 | import { sql as drizzleSql } from "drizzle-orm"; |
| 3 | +import * as Cause from "effect/Cause"; | |
| 3 | 4 | import * as Crypto from "effect/Crypto"; |
| 4 | 5 | import * as Context from "effect/Context"; |
| 5 | 6 | import * as DateTime from "effect/DateTime"; |
| @@ -239,8 +240,8 @@ export const relayEnvironmentAuthLayer = Layer.effect( · 233 unmodified lines | ||
| 239 | 240 | const token = readHttpAuthorizationCredential(credential); |
| 240 | 241 | const principal = yield* credentials.authenticate(token).pipe( |
| 241 | 242 | Effect.catchTags({ |
| 242 | − EnvironmentCredentialAuthenticatePersistenceError: () => | |
| 243 | − relayInternalErrorResponse("persistence_failed"), | |
| 243 | + EnvironmentCredentialAuthenticatePersistenceError: (error) => | |
| 244 | + relayInternalErrorResponse("persistence_failed", error), | |
| 244 | 245 | }), |
| 245 | 246 | ); |
| 246 | 247 | if (principal._tag === "None") { |
| @@ -353,7 +354,7 @@ export const healthApi = HttpApiBuilder.group( · 106 unmodified lines | ||
| 353 | 354 | yield* db.execute(drizzleSql`SELECT 1`); |
| 354 | 355 | return { ok: true, service: "relay" as const }; |
| 355 | 356 | }, |
| 356 | − Effect.catch(() => relayInternalErrorResponse("database_unavailable")), | |
| 357 | + Effect.catch((error) => relayInternalErrorResponse("database_unavailable", error)), | |
| 357 | 358 | ), |
| 358 | 359 | ); |
| 359 | 360 | }), |
| @@ -512,7 +513,7 @@ export const clientApi = HttpApiBuilder.group( · 152 unmodified lines | ||
| 512 | 513 | const now = yield* DateTime.now; |
| 513 | 514 | const expiresAt = DateTime.add(now, { minutes: 5 }); |
| 514 | 515 | const jti = yield* crypto.randomUUIDv4.pipe( |
| 515 | − Effect.catch(() => relayInternalErrorResponse("internal_error")), | |
| 516 | + Effect.catch((error) => relayInternalErrorResponse("internal_error", error)), | |
| 516 | 517 | ); |
| 517 | 518 | const challenge = yield* relayTokens |
| 518 | 519 | .issueLinkChallenge({ |
| @@ -522,7 +523,7 @@ export const clientApi = HttpApiBuilder.group( · 3 unmodified lines | ||
| 522 | 523 | issuedAtEpochSeconds: Math.floor(now.epochMilliseconds / 1_000), |
| 523 | 524 | expiresAtEpochSeconds: Math.floor(expiresAt.epochMilliseconds / 1_000), |
| 524 | 525 | }) |
| 525 | − .pipe(Effect.catch(() => relayInternalErrorResponse("internal_error"))); | |
| 526 | + .pipe(Effect.catch((error) => relayInternalErrorResponse("internal_error", error))); | |
| 526 | 527 | return { challenge, expiresAt: DateTime.formatIso(expiresAt) }; |
| 527 | 528 | }, mapRelayCommonApiErrors("not_authorized")), |
| 528 | 529 | ) |
| @@ -536,7 +537,9 @@ export const clientApi = HttpApiBuilder.group( · 7 unmodified lines | ||
| 536 | 537 | userId, |
| 537 | 538 | environmentId: params.environmentId, |
| 538 | 539 | }) |
| 539 | − .pipe(Effect.catch(() => relayInternalErrorResponse("upstream_unavailable"))); | |
| 540 | + .pipe( | |
| 541 | + Effect.catch((error) => relayInternalErrorResponse("upstream_unavailable", error)), | |
| 542 | + ); | |
| 540 | 543 | const link = yield* links.getForUser({ |
| 541 | 544 | userId, |
| 542 | 545 | environmentId: params.environmentId, |
| @@ -596,7 +599,7 @@ export const tokenApi = HttpApiBuilder.group( · 53 unmodified lines | ||
| 596 | 599 | const now = yield* DateTime.now; |
| 597 | 600 | const expiresAt = DateTime.addDuration(now, RelayTokens.RELAY_DPOP_ACCESS_TOKEN_TTL); |
| 598 | 601 | const jti = yield* crypto.randomUUIDv4.pipe( |
| 599 | − Effect.catch(() => relayInternalErrorResponse("internal_error")), | |
| 602 | + Effect.catch((error) => relayInternalErrorResponse("internal_error", error)), | |
| 600 | 603 | ); |
| 601 | 604 | return { |
| 602 | 605 | access_token: yield* relayTokens |
| @@ -609,7 +612,7 @@ export const tokenApi = HttpApiBuilder.group( · 6 unmodified lines | ||
| 609 | 612 | clientId: args.payload.client_id, |
| 610 | 613 | scopes: requestedScopes, |
| 611 | 614 | }) |
| 612 | − .pipe(Effect.catch(() => relayInternalErrorResponse("internal_error"))), | |
| 615 | + .pipe(Effect.catch((error) => relayInternalErrorResponse("internal_error", error))), | |
| 613 | 616 | issued_token_type: RelayAccessTokenType, |
| 614 | 617 | token_type: "DPoP" as const, |
| 615 | 618 | expires_in: Duration.toSeconds(RelayTokens.RELAY_DPOP_ACCESS_TOKEN_TTL), |
| @@ -901,6 +904,50 @@ const currentTraceId = Effect.currentParentSpan.pipe( · 285 unmodified lines | ||
| 901 | 904 | Effect.orElseSucceed(() => "unavailable"), |
| 902 | 905 | ); |
| 903 | 906 | |
| 907 | +function relayApiErrorTag(error: unknown): string { | |
| 908 | + if ( | |
| 909 | + typeof error === "object" && | |
| 910 | + error !== null && | |
| 911 | + "_tag" in error && | |
| 912 | + typeof error._tag === "string" | |
| 913 | + ) { | |
| 914 | + return error._tag; | |
| 915 | + } | |
| 916 | + if (error instanceof Error && error.name.length > 0) { | |
| 917 | + return error.name; | |
| 918 | + } | |
| 919 | + return typeof error; | |
| 920 | +} | |
| 921 | + | |
| 922 | +function safeRelayApiLogCode(value: unknown): string | undefined { | |
| 923 | + return typeof value === "string" && value.length <= 64 && /^[a-z0-9._-]+$/iu.test(value) | |
| 924 | + ? value | |
| 925 | + : undefined; | |
| 926 | +} | |
| 927 | + | |
| 928 | +function relayApiProjectionResponseFields(error: unknown) { | |
| 929 | + if (typeof error !== "object" || error === null) { | |
| 930 | + return {}; | |
| 931 | + } | |
| 932 | + const code = "code" in error ? safeRelayApiLogCode(error.code) : undefined; | |
| 933 | + const reason = "reason" in error ? safeRelayApiLogCode(error.reason) : undefined; | |
| 934 | + return { | |
| 935 | + ...(code === undefined ? {} : { responseCode: code }), | |
| 936 | + ...(reason === undefined ? {} : { responseReason: reason }), | |
| 937 | + }; | |
| 938 | +} | |
| 939 | + | |
| 940 | +function logRelayApiProjection(cause: unknown, responseError: unknown, traceId: string) { | |
| 941 | + return Effect.logError("relay API failure projected to wire response", Cause.fail(cause)).pipe( | |
| 942 | + Effect.annotateLogs({ | |
| 943 | + traceId, | |
| 944 | + sourceErrorTag: relayApiErrorTag(cause), | |
| 945 | + responseErrorTag: relayApiErrorTag(responseError), | |
| 946 | + ...relayApiProjectionResponseFields(responseError), | |
| 947 | + }), | |
| 948 | + ); | |
| 949 | +} | |
| 950 | + | |
| 904 | 951 | const RelayCommonPersistenceError = Schema.Union([ |
| 905 | 952 | Devices.DeviceRegistrationPersistenceError, |
| 906 | 953 | Devices.DeviceUnregistrationPersistenceError, |
| @@ -930,15 +977,16 @@ type MapRelayCommonApiError<E> = · 23 unmodified lines | ||
| 930 | 977 | | (Extract<E, HttpApiError.Unauthorized> extends never ? never : RelayAuthInvalidError) |
| 931 | 978 | | (Extract<E, RelayCommonPersistenceError> extends never ? never : RelayInternalError); |
| 932 | 979 | |
| 933 | −function relayInternalErrorResponse(reason: RelayInternalError["reason"]) { | |
| 934 | − return currentTraceId.pipe( | |
| 935 | − Effect.flatMap((traceId) => | |
| 936 | − Effect.fail(new RelayInternalError({ code: "internal_error", reason, traceId })), | |
| 937 | − ), | |
| 938 | − ); | |
| 980 | +function relayInternalErrorResponse(reason: RelayInternalError["reason"], cause: unknown) { | |
| 981 | + return Effect.gen(function* () { | |
| 982 | + const traceId = yield* currentTraceId; | |
| 983 | + const responseError = new RelayInternalError({ code: "internal_error", reason, traceId }); | |
| 984 | + yield* logRelayApiProjection(cause, responseError, traceId); | |
| 985 | + return yield* responseError; | |
| 986 | + }); | |
| 939 | 987 | } |
| 940 | 988 | |
| 941 | −function mapRelayCommonApiErrors(authReason: RelayAuthInvalidReason) { | |
| 989 | +export function mapRelayCommonApiErrors(authReason: RelayAuthInvalidReason) { | |
| 942 | 990 | const mapError = Effect.fnUntraced(function* <E>(error: E) { |
| 943 | 991 | const traceId = yield* currentTraceId; |
| 944 | 992 | if (isHttpUnauthorized(error)) { |
| @@ -951,13 +999,13 @@ function mapRelayCommonApiErrors(authReason: RelayAuthInvalidReason) { · 6 unmodified lines | ||
| 951 | 999 | ); |
| 952 | 1000 | } |
| 953 | 1001 | if (isRelayCommonPersistenceError(error)) { |
| 954 | − return yield* Effect.fail( | |
| 955 | − new RelayInternalError({ | |
| 956 | − code: "internal_error", | |
| 957 | − reason: "persistence_failed", | |
| 958 | − traceId, | |
| 959 | − }) as MapRelayCommonApiError<E>, | |
| 960 | − ); | |
| 1002 | + const responseError = new RelayInternalError({ | |
| 1003 | + code: "internal_error", | |
| 1004 | + reason: "persistence_failed", | |
| 1005 | + traceId, | |
| 1006 | + }); | |
| 1007 | + yield* logRelayApiProjection(error, responseError, traceId); | |
| 1008 | + return yield* Effect.fail(responseError as MapRelayCommonApiError<E>); | |
| 961 | 1009 | } |
| 962 | 1010 | |
| 963 | 1011 | return yield* Effect.fail(error as MapRelayCommonApiError<E>); |
| @@ -989,7 +1037,19 @@ type CatchTagCases<E, Cases> = { · 25 unmodified lines | ||
| 989 | 1037 | ) => Effect.Effect<never, MappedTagError<Cases>>; |
| 990 | 1038 | } & (unknown extends E ? {} : { readonly [K in Exclude<keyof Cases, TaggedErrorTag<E>>]: never }); |
| 991 | 1039 | |
| 992 | −function mapErrorTags< | |
| 1040 | +const relayApiProjectedFailureLogTags = new Set([ | |
| 1041 | + "ManagedEndpointProvisioningNotConfigured", | |
| 1042 | + "ManagedEndpointProvisioningFailed", | |
| 1043 | + "EnvironmentLinkUpsertPersistenceError", | |
| 1044 | + "EnvironmentCredentialCreatePersistenceError", | |
| 1045 | + "DpopProofReplayPersistenceError", | |
| 1046 | + "EnvironmentMintRequestFailed", | |
| 1047 | + "EnvironmentMintRequestTimedOut", | |
| 1048 | + "EnvironmentMintResponseInvalid", | |
| 1049 | + "ApnsDeliveryQueueSendError", | |
| 1050 | +]); | |
| 1051 | + | |
| 1052 | +export function mapErrorTags< | |
| 993 | 1053 | E, |
| 994 | 1054 | Cases extends MapErrorTagCases<E> & |
| 995 | 1055 | (unknown extends E ? {} : { readonly [K in Exclude<keyof Cases, TaggedErrorTag<E>>]: never }), |
| @@ -1000,7 +1060,15 @@ function mapErrorTags< · 4 unmodified lines | ||
| 1000 | 1060 | (error: never, traceId: string) => MappedTagError<Cases> |
| 1001 | 1061 | >, |
| 1002 | 1062 | (makeError) => (error: never) => |
| 1003 | − currentTraceId.pipe(Effect.flatMap((traceId) => Effect.fail(makeError(error, traceId)))), | |
| 1063 | + currentTraceId.pipe( | |
| 1064 | + Effect.flatMap((traceId) => { | |
| 1065 | + const responseError = makeError(error, traceId); | |
| 1066 | + const logProjection = relayApiProjectedFailureLogTags.has(relayApiErrorTag(error)) | |
| 1067 | + ? logRelayApiProjection(error, responseError, traceId) | |
| 1068 | + : Effect.void; | |
| 1069 | + return logProjection.pipe(Effect.andThen(Effect.fail(responseError))); | |
| 1070 | + }), | |
| 1071 | + ), | |
| 1004 | 1072 | ) as CatchTagCases<E, Cases>; |
| 1005 | 1073 | |
| 1006 | 1074 | return <A, R>( |