@@ -17,7 +17,7 @@ import java.nio.charset.StandardCharsets
1717/* *
1818 * @author ihsan on 09/02/2017.
1919 */
20- open class Printer protected constructor() {
20+ class Printer private constructor() {
2121 companion object {
2222 private const val JSON_INDENT = 3
2323 private val LINE_SEPARATOR = System .getProperty(" line.separator" )
@@ -40,7 +40,9 @@ open class Printer protected constructor() {
4040 }
4141
4242 fun printJsonRequest (builder : LoggingInterceptor .Builder , body : RequestBody ? , url : String , header : Headers , method : String ) {
43- val requestBody = LINE_SEPARATOR + BODY_TAG + LINE_SEPARATOR + bodyToString(body, header)
43+ val requestBody = body?.let {
44+ LINE_SEPARATOR + BODY_TAG + LINE_SEPARATOR + bodyToString(body, header)
45+ } ? : " "
4446 val tag = builder.getTag(true )
4547 if (builder.logger == null ) I .log(builder.type, tag, REQUEST_UP_LINE , builder.isLogHackEnable)
4648 logLines(builder.type, tag, arrayOf(URL_TAG + url), builder.logger, false , builder.isLogHackEnable)
@@ -77,7 +79,7 @@ open class Printer protected constructor() {
7779 val headers = response.headers
7880 val contentLength = responseBody.contentLength()
7981 if (! response.promisesBody()) {
80- return " End request - Promoses Body"
82+ return " End request - Promises Body"
8183 } else if (bodyHasUnknownEncoding(response.headers)) {
8284 return " encoded body omitted"
8385 } else {
@@ -151,7 +153,7 @@ open class Printer protected constructor() {
151153 headers.forEach { pair ->
152154 builder.append(" ${pair.first} : ${pair.second} " ).append(N )
153155 }
154- return builder.toString()
156+ return builder.dropLast( 1 ). toString()
155157 }
156158
157159 private fun logLines (type : Int , tag : String , lines : Array <String >, logger : Logger ? ,
@@ -203,7 +205,7 @@ open class Printer protected constructor() {
203205 } catch (e: IOException ) {
204206 " {\" err\" : \" " + e.message + " \" }"
205207 }
206- } ? : " { \" err \" : \" $requestBody \" } "
208+ } ? : " "
207209 }
208210
209211 private fun bodyHasUnknownEncoding (headers : Headers ): Boolean {
0 commit comments