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 6fc75779e4..a82750315c 100644 --- a/zio-http/shared/src/main/scala/zio/http/ErrorResponseConfig.scala +++ b/zio-http/shared/src/main/scala/zio/http/ErrorResponseConfig.scala @@ -22,12 +22,39 @@ final case class ErrorResponseConfig( withStackTrace: Boolean = false, maxStackTraceDepth: Int = 10, errorFormat: ErrorResponseConfig.ErrorFormat = ErrorResponseConfig.ErrorFormat.Html, - logCodecErrors: Boolean = false, -) + 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 copyWithLog( + 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 } - object ErrorFormat { + object ErrorFormat { case object Text extends ErrorFormat { val mediaType: MediaType = MediaType.text.`plain` } case object Html extends ErrorFormat { val mediaType: MediaType = MediaType.text.html } case object Json extends ErrorFormat { val mediaType: MediaType = MediaType.application.json } @@ -38,7 +65,7 @@ object ErrorResponseConfig { withErrorBody: Boolean, withStackTrace: Boolean, maxStackTraceDepth: Int, - errorFormat: ErrorFormat, + errorFormat: ErrorFormat ): ErrorResponseConfig = new ErrorResponseConfig(withErrorBody, withStackTrace, maxStackTraceDepth, errorFormat, logCodecErrors = false)