@@ -17,7 +17,7 @@ import java.nio.charset.StandardCharsets
17
17
/* *
18
18
* @author ihsan on 09/02/2017.
19
19
*/
20
- open class Printer protected constructor() {
20
+ class Printer private constructor() {
21
21
companion object {
22
22
private const val JSON_INDENT = 3
23
23
private val LINE_SEPARATOR = System .getProperty(" line.separator" )
@@ -40,7 +40,9 @@ open class Printer protected constructor() {
40
40
}
41
41
42
42
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
+ } ? : " "
44
46
val tag = builder.getTag(true )
45
47
if (builder.logger == null ) I .log(builder.type, tag, REQUEST_UP_LINE , builder.isLogHackEnable)
46
48
logLines(builder.type, tag, arrayOf(URL_TAG + url), builder.logger, false , builder.isLogHackEnable)
@@ -77,7 +79,7 @@ open class Printer protected constructor() {
77
79
val headers = response.headers
78
80
val contentLength = responseBody.contentLength()
79
81
if (! response.promisesBody()) {
80
- return " End request - Promoses Body"
82
+ return " End request - Promises Body"
81
83
} else if (bodyHasUnknownEncoding(response.headers)) {
82
84
return " encoded body omitted"
83
85
} else {
@@ -151,7 +153,7 @@ open class Printer protected constructor() {
151
153
headers.forEach { pair ->
152
154
builder.append(" ${pair.first} : ${pair.second} " ).append(N )
153
155
}
154
- return builder.toString()
156
+ return builder.dropLast( 1 ). toString()
155
157
}
156
158
157
159
private fun logLines (type : Int , tag : String , lines : Array <String >, logger : Logger ? ,
@@ -203,7 +205,7 @@ open class Printer protected constructor() {
203
205
} catch (e: IOException ) {
204
206
" {\" err\" : \" " + e.message + " \" }"
205
207
}
206
- } ? : " { \" err \" : \" $requestBody \" } "
208
+ } ? : " "
207
209
}
208
210
209
211
private fun bodyHasUnknownEncoding (headers : Headers ): Boolean {
0 commit comments