Skip to content

Commit

Permalink
Enable IppClient.onExceptionSaveMessages by default. Log path of save…
Browse files Browse the repository at this point in the history
…d files with INFO level. This should make it easier for library users and me to work on issues.
  • Loading branch information
gmuth committed Sep 10, 2024
1 parent 73c2e80 commit 0ee7b80
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
13 changes: 8 additions & 5 deletions src/main/kotlin/de/gmuth/ipp/client/IppClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ open class IppClient(val config: IppConfig = IppConfig()) : IppExchange {
var responseInterceptor: IppResponseInterceptor? = null
var saveMessages: Boolean = false
var saveMessagesDirectory = File("ipp-messages")
var onExceptionSaveMessages: Boolean = false
var onExceptionSaveMessages: Boolean = true
var throwWhenNotSuccessful: Boolean = true
var disconnectAfterHttpPost: Boolean = false

Expand Down Expand Up @@ -76,7 +76,7 @@ open class IppClient(val config: IppConfig = IppConfig()) : IppExchange {
logger.fine { "Send '$operation' request to $printerOrJobUri" }
httpPost(toHttpUri(printerOrJobUri), request).also {
logger.finer { "Req #${request.requestId} @${printerOrJobUri.host}: $request => $it" }
if(logger.isLoggable(FINEST)) {
if (logger.isLoggable(FINEST)) {
request.log(logger, FINEST, ">>> ")
it.log(logger, FINEST, "<<< ")
}
Expand Down Expand Up @@ -129,10 +129,13 @@ open class IppClient(val config: IppConfig = IppConfig()) : IppExchange {
if (containsGroup(Unsupported)) unsupportedGroup.values.forEach { logger.warning() { "Unsupported: $it" } }
if (!isSuccessful()) {
IppRegistrationsSection2.validate(request)
if (throwWhenNotSuccessful) {
throw if (status == ClientErrorNotFound) ClientErrorNotFoundException(request, response)
val exception =
if (status == ClientErrorNotFound) ClientErrorNotFoundException(request, response)
else IppOperationException(request, response)
}
if (onExceptionSaveMessages)
exception.saveMessages("${request.operation}_${status}_${request.requestId}")
if (throwWhenNotSuccessful)
throw exception
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/de/gmuth/ipp/client/IppPrinter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -477,9 +477,9 @@ class IppPrinter(
}

fun checkNotifyEvents(notifyEvents: Collection<String>?) = notifyEvents?.let {
if (!attributes.containsKey("notify-events-supported"))
throw IppException("Printer does not support event notifications.")
if (it.isNotEmpty() && it.first() != "all") {
if (!attributes.containsKey("notify-events-supported"))
throw IppException("Printer does not support request parameter 'notifyEvents'.")
checkIfValueIsSupported("notify-events", it, true)
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/de/gmuth/ipp/core/IppMessage.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.gmuth.ipp.core

/**
* Copyright (c) 2020-2023 Gerhard Muth
* Copyright (c) 2020-2024 Gerhard Muth
*/

import de.gmuth.ipp.core.IppTag.*
Expand Down Expand Up @@ -166,7 +166,7 @@ abstract class IppMessage() {
throw IppException("No raw bytes to save. You must call read/decode or write/encode before.")
} else {
file.writeBytes(rawBytes!!)
logger.fine { "Saved ${file.path} (${file.length()} bytes)" }
logger.info { "Saved ${file.path} (${file.length()} bytes)" }
}

fun write(bufferedWriter: BufferedWriter, title: String? = null) {
Expand Down

0 comments on commit 0ee7b80

Please sign in to comment.