From 84d42b06663fdba788075e8ccd63020d614f1a38 Mon Sep 17 00:00:00 2001 From: Vamshi Maskuri <117595548+varshith257@users.noreply.github.com> Date: Mon, 11 Nov 2024 09:55:46 +0530 Subject: [PATCH] add review comments --- .../scala/zio/http/ErrorResponseConfig.scala | 45 +++++-------------- 1 file changed, 10 insertions(+), 35 deletions(-) diff --git a/zio-http/shared/src/main/scala/zio/http/ErrorResponseConfig.scala b/zio-http/shared/src/main/scala/zio/http/ErrorResponseConfig.scala index 4874660111..6fc75779e4 100644 --- a/zio-http/shared/src/main/scala/zio/http/ErrorResponseConfig.scala +++ b/zio-http/shared/src/main/scala/zio/http/ErrorResponseConfig.scala @@ -23,34 +23,7 @@ final case class ErrorResponseConfig( maxStackTraceDepth: Int = 10, errorFormat: ErrorResponseConfig.ErrorFormat = ErrorResponseConfig.ErrorFormat.Html, logCodecErrors: Boolean = false, -) { - - /** - * Backward-compatible copy method for compatibility with older code. - * - * Omits the new `logCodecErrors` parameter, which defaults to `false` in - * older usage scenarios. - */ - def copy( - withErrorBody: Boolean = this.withErrorBody, - withStackTrace: Boolean = this.withStackTrace, - maxStackTraceDepth: Int = this.maxStackTraceDepth, - errorFormat: ErrorResponseConfig.ErrorFormat = this.errorFormat, - ): ErrorResponseConfig = - new ErrorResponseConfig(withErrorBody, withStackTrace, maxStackTraceDepth, errorFormat, logCodecErrors) - - /** - * Full copy method including all parameters. - */ - def copy( - withErrorBody: Boolean = this.withErrorBody, - withStackTrace: Boolean = this.withStackTrace, - maxStackTraceDepth: Int = this.maxStackTraceDepth, - errorFormat: ErrorResponseConfig.ErrorFormat = this.errorFormat, - logCodecErrors: Boolean = this.logCodecErrors, - ): ErrorResponseConfig = - new ErrorResponseConfig(withErrorBody, withStackTrace, maxStackTraceDepth, errorFormat, logCodecErrors) -} +) object ErrorResponseConfig { sealed trait ErrorFormat { val mediaType: MediaType } @@ -60,13 +33,7 @@ object ErrorResponseConfig { case object Json extends ErrorFormat { val mediaType: MediaType = MediaType.application.json } } - val default: ErrorResponseConfig = ErrorResponseConfig() - val debugConfig: ErrorResponseConfig = - ErrorResponseConfig(withErrorBody = true, withStackTrace = true, maxStackTraceDepth = 0, logCodecErrors = true) - - private[http] val configRef: FiberRef[ErrorResponseConfig] = - FiberRef.unsafe.make(default)(Unsafe) - + // Backward-compatible apply method for older usage, without logCodecErrors def apply( withErrorBody: Boolean, withStackTrace: Boolean, @@ -75,6 +42,14 @@ object ErrorResponseConfig { ): ErrorResponseConfig = new ErrorResponseConfig(withErrorBody, withStackTrace, maxStackTraceDepth, errorFormat, logCodecErrors = false) + val default: ErrorResponseConfig = ErrorResponseConfig() + + val debugConfig: ErrorResponseConfig = + ErrorResponseConfig(withErrorBody = true, withStackTrace = true, maxStackTraceDepth = 0, logCodecErrors = true) + + private[http] val configRef: FiberRef[ErrorResponseConfig] = + FiberRef.unsafe.make(default)(Unsafe) + val debug: HandlerAspect[Any, Unit] = Middleware.runBefore(setConfig(debugConfig))