From b68a9e0fdadc449d2353b004dbea34015bc65d05 Mon Sep 17 00:00:00 2001 From: Chris Wilkinson Date: Tue, 12 Dec 2023 11:57:57 +0000 Subject: [PATCH] Make it easier to see why requests are invalid --- src/index.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 08cd411..6a8cd82 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,5 @@ import { HttpClient, HttpServer, Runtime } from '@effect/platform-node' -import { Schema } from '@effect/schema' +import { Schema, TreeFormatter } from '@effect/schema' import { Effect, Layer } from 'effect' import { createServer } from 'node:http' import * as CoarNotify from './CoarNotify.js' @@ -80,7 +80,16 @@ const serve = HttpServer.router.empty.pipe( return yield* _(HttpServer.response.empty({ status: 201 })) }).pipe( Effect.catchTags({ - ParseError: () => HttpServer.response.empty({ status: 400 }), + ParseError: error => + Effect.gen(function* (_) { + yield* _( + Effect.logInfo('Invalid request').pipe( + Effect.annotateLogs({ message: TreeFormatter.formatErrors(error.errors) }), + ), + ) + + return HttpServer.response.empty({ status: 400 }) + }), RedisError: error => Effect.gen(function* (_) { yield* _(