Hello folks! Is there a better way to do this? ```...
# codereview
x
Hello folks! Is there a better way to do this?
Copy code
class Response(val message: String, val path: String) {
  val timestamp: Long = Instant.now().toEpochMilli()

  var status: Int = 0

  lateinit var error: String

  companion object {
    fun clientError(message: String, path: String): Response {
      return Response(message, path).apply { status = 400; error = "Bad Request" }
    }

    fun serverError(message: String, path: String): Response {
      return Response(message, path).apply { status = 500; error = "Internal Server Error" }
    }
  }
}
s
kinda curious, why are you making
status
and
error
`var`s? Could you not just put them in the primary constructor and use named parameters?
Also, yeah, a
sealed class
could be useful here as far as matching and whatnot go
1
There are also good examples of the
Result<T>
pattern if that’s something you might be interested in
👌 1