Skip to content

Commit

Permalink
constructor with IppStatus and statusMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
gmuth committed Oct 6, 2024
1 parent 8b15ea5 commit f13e5ed
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/main/kotlin/de/gmuth/ipp/client/IppOperationException.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import de.gmuth.ipp.core.IppRequest
import de.gmuth.ipp.core.IppResponse
import de.gmuth.ipp.core.IppStatus
import de.gmuth.ipp.core.IppStatus.ClientErrorNotFound
import de.gmuth.ipp.core.IppString
import de.gmuth.ipp.core.IppTag.Operation
import java.io.File
import java.util.logging.Level
Expand All @@ -20,6 +21,19 @@ open class IppOperationException(
cause: Throwable? = null
) : IppExchangeException(request, message, cause) {

constructor(
request: IppRequest,
status: IppStatus,
message: String,
messageLanguage: String = "en",
cause: Throwable? = null
) : this(
request,
IppResponse(status, statusMessage = IppString("$message: ${cause?.message}", messageLanguage)),
message,
cause
)

class ClientErrorNotFoundException(request: IppRequest, response: IppResponse) :
IppOperationException(request, response) {
init {
Expand All @@ -29,16 +43,15 @@ open class IppOperationException(
}

companion object {
fun defaultMessage(request: IppRequest, response: IppResponse) = StringBuilder().run {
fun defaultMessage(request: IppRequest, response: IppResponse) = StringBuilder().apply {
append("${request.operation} failed")
with(response) {
append(": '$status'")
if (containsGroup(Operation) && operationGroup.containsKey("status-message")) {
append(", $statusMessage")
}
}
toString()
}
}.toString()
}

fun statusIs(status: IppStatus) = response.status == status
Expand Down

0 comments on commit f13e5ed

Please sign in to comment.