I am using 2 classes to handle error statuses, the Spring's own org.springframework.http.HttpStatus
and my custom ErrorStatus
:
enum class ErrorStatus(val code: Int, val reasonPhrase: String) {
ELEMENT_NOT_FOUND(1404, "Element not found"),
UNKNOWN_ERROR(1000, "Unknown Error"),
}
I would like to seal both classes using:
sealed interface Error
It's simple to do this with my class: enum class ErrorStatus(val code: Int, val reasonPhrase: String) : Error {
But is it possible to mark HttpStatus
class as a part of this sealed interface?
No, you cannot apply an interface to a class externally. Also, members of a sealed class or interface have to be defined inside the same project module as the sealed class or interface.
I would wrap the other class.
You might consider making it an inline wrapper class: