Skip to content

Commit dbb4569

Browse files
committed
♻️ refactor: update codebase #5 #2
1 parent 2bd0e3b commit dbb4569

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

Diff for: plugin/src/main/groovy/org/bot4j/telegram/message/HttpBuilder.java

+32
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ protected static class Index {
3434
public static final String HEADER_INDEX = "header_index";
3535
public static final String STATUS_INDEX = "code_index";
3636
public static final String API_DESC_INDEX = "api_desc_index";
37+
public static final String CAUSE_INDEX = "cause_index";
38+
public static final String REQUEST_ID_INDEX = "request_id_index";
3739
}
3840

3941
public HttpBuilder apiDesc(String desc) {
@@ -136,6 +138,29 @@ public HttpBuilder timezone(TimezoneType timezone) {
136138
return this.timezone(timezone.getTimeZoneId());
137139
}
138140

141+
public HttpBuilder cause(Throwable e) {
142+
if (e == null) {
143+
return this;
144+
}
145+
return this.cause(e.getMessage());
146+
}
147+
148+
public HttpBuilder cause(String e) {
149+
if (String4j.isEmpty(e)) {
150+
return this;
151+
}
152+
this.placeholders.put(Index.CAUSE_INDEX, e);
153+
return this;
154+
}
155+
156+
public HttpBuilder requestId(String requestId) {
157+
if (String4j.isEmpty(requestId)) {
158+
return this;
159+
}
160+
this.placeholders.put(Index.REQUEST_ID_INDEX, requestId);
161+
return this;
162+
}
163+
139164
@SuppressWarnings({"unchecked"})
140165
@Override
141166
public String toString() {
@@ -180,6 +205,9 @@ public String toString() {
180205
this.code(String4j.trimWhitespace(url));
181206
}
182207
this.line(2);
208+
if (this.placeholders.containsKey(Index.REQUEST_ID_INDEX)) {
209+
this.bold("SSID:").code((String) this.placeholders.get(Index.REQUEST_ID_INDEX)).line();
210+
}
183211
if (Object4j.allNotNull(this.start)) {
184212
if (String4j.isEmpty(this.timezone)) {
185213
this.bold("RFT:").timestamp(this.start).line();
@@ -217,6 +245,10 @@ public String toString() {
217245
Map<String, Object> request = (Map<String, Object>) Json4j.toMapFrom(this.placeholders.get(Index.RESPONSE_INDEX));
218246
this.bold("Resp:").preformatted("json", request);
219247
}
248+
if (this.placeholders.containsKey(Index.CAUSE_INDEX)) {
249+
this.line();
250+
this.bold("Ex:").preformatted("java", (String) this.placeholders.get(Index.CAUSE_INDEX));
251+
}
220252
return super.toString();
221253
}
222254
}

0 commit comments

Comments
 (0)