Skip to content

Commit 049f80e

Browse files
committed
Add logger to Response
1 parent 727cbb1 commit 049f80e

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

src/express/http/request/RequestUtils.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,7 @@ static HashMap<String, String> parseRawQuery(String rawQuery) {
8383

8484
try {
8585
querys.put(URLDecoder.decode(key.toString(), "UTF-8"), URLDecoder.decode(val.toString(), "UTF8"));
86-
} catch (UnsupportedEncodingException e) {
87-
e.printStackTrace();
88-
// TODO: Handle error
89-
}
86+
} catch (UnsupportedEncodingException ignored) {}
9087

9188
key.setLength(0);
9289
val.setLength(0);

src/express/http/response/Response.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import java.nio.file.Path;
1616
import java.nio.file.StandardOpenOption;
1717
import java.util.List;
18+
import java.util.logging.Level;
19+
import java.util.logging.Logger;
1820

1921
/**
2022
* @author Simon Reinisch
@@ -25,6 +27,7 @@ public class Response {
2527
private final HttpExchange HTTP_EXCHANGE;
2628
private final OutputStream BODY;
2729
private final Headers HEADER;
30+
private final Logger LOGGER;
2831

2932
private String contentType;
3033
private boolean isClose;
@@ -37,6 +40,7 @@ public class Response {
3740
isClose = false;
3841
contentLength = 0;
3942
status = 200;
43+
LOGGER = Logger.getLogger(getClass().getSimpleName());
4044
}
4145

4246
public Response(HttpExchange exchange) {
@@ -174,8 +178,7 @@ public void send(String s) {
174178
try {
175179
this.BODY.write(s.getBytes());
176180
} catch (IOException e) {
177-
// TODO: Handle error
178-
e.printStackTrace();
181+
LOGGER.log(Level.INFO, "Failed to write charsequence to client.", e);
179182
}
180183

181184
close();
@@ -212,8 +215,7 @@ public void send(@NotNull Path file) {
212215
fis.close();
213216

214217
} catch (IOException e) {
215-
// TODO: Handle error
216-
e.printStackTrace();
218+
LOGGER.log(Level.INFO, "Failed to pipe file to outputstream.", e);
217219
}
218220

219221
close();
@@ -236,8 +238,7 @@ private void sendHeaders() {
236238
this.HEADER.set("Content-Type", contentType);
237239
this.HTTP_EXCHANGE.sendResponseHeaders(status, contentLength);
238240
} catch (IOException e) {
239-
// TODO: Handle error
240-
e.printStackTrace();
241+
LOGGER.log(Level.INFO, "Failed to send headers.", e);
241242
}
242243
}
243244

@@ -246,8 +247,7 @@ private void close() {
246247
this.BODY.close();
247248
this.isClose = true;
248249
} catch (IOException e) {
249-
// TODO: Handle error
250-
e.printStackTrace();
250+
LOGGER.log(Level.INFO, "Failed to close outputstream.", e);
251251
}
252252
}
253253

0 commit comments

Comments
 (0)