| 1 | import { assert, describe, it } from "@effect/vitest" |
| 2 | import { Cause, Effect, ErrorReporter, Exit, Schema } from "effect" |
| 3 | import { HttpApiError } from "effect/http-api" |
| 4 | |
| 5 | describe("HttpApiError", () => { |
| 6 | it.effect("does not report payload schema-validation failures", () => |
| 7 | Effect.gen(function*() { |
| 8 | const schemaError = yield* HttpApiError.HttpApiSchemaError.wrap( |
| 9 | "Payload", |
| 10 | Schema.decodeUnknownEffect(Schema.Struct({ name: Schema.String }))({ name: 123 }) |
| 11 | ).pipe(Effect.flip) |
| 12 | const reports: Array<Cause.Cause<unknown>> = [] |
| 13 | const reporter = ErrorReporter.make(({ cause }) => reports.push(cause)) |
| 14 | |
| 15 | const exit = yield* Effect.fail(schemaError).pipe( |
| 16 | Effect.withErrorReporting, |
| 17 | Effect.provide(ErrorReporter.layer([reporter])), |
| 18 | Effect.exit |
| 19 | ) |
| 20 | |
| 21 | assert.instanceOf(schemaError, HttpApiError.HttpApiSchemaError) |
| 22 | assert.strictEqual(schemaError.kind, "Payload") |
| 23 | assert.isTrue(Exit.isFailure(exit)) |
| 24 | if (Exit.isFailure(exit)) { |
| 25 | assert.strictEqual(Cause.squash(exit.cause), schemaError) |
| 26 | } |
| 27 | assert.deepStrictEqual(reports, []) |
| 28 | })) |
| 29 | }) |