Skip to content

Commit 45a0945

Browse files
committed
Add error messages
1 parent d391620 commit 45a0945

File tree

4 files changed

+10
-7
lines changed

4 files changed

+10
-7
lines changed

src/main/java/httpserver/Hasher.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ public boolean matches(byte[] input, String hash) {
99
}
1010

1111
public String getHash(byte[] input) {
12-
MessageDigest messageDigest = null;
1312
try {
14-
messageDigest = MessageDigest.getInstance("SHA1");
13+
MessageDigest messageDigest = MessageDigest.getInstance("SHA1");
14+
byte[] hash = messageDigest.digest(input);
15+
return bytesToHex(hash);
1516
} catch (NoSuchAlgorithmException e) {
16-
e.printStackTrace();
17+
System.out.println("Unable to get hash.");
18+
return "";
1719
}
18-
byte[] hash = messageDigest.digest(input);
19-
return bytesToHex(hash);
2020
}
2121

2222
private String bytesToHex(byte[] hash) {

src/main/java/httpserver/Logger.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ public void log(String logString) {
2727
private void createFileIfDoesntExist(Path path) {
2828
try {
2929
fileOperator.createFileAtPath(path);
30-
} catch (IOException e) {}
30+
} catch (IOException e) {
31+
System.out.println("Coudln't create log file");
32+
}
3133
}
3234

3335
public byte[] readLog() {

src/main/java/httpserver/Server.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public void acceptConnection(ExecutorService executorService, SocketHandlerFacto
2020
SocketHandler socketHandler = socketHandlerFactory.newSocketHandler(appConfig, clientSocket);
2121
executorService.submit(socketHandler);
2222
} catch (IOException e) {
23+
System.out.println("Server socket error");
2324
e.printStackTrace();
2425
}
2526
}

src/main/java/httpserver/file/PathExaminer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public Path[] directoryContents(Path dir) {
5050
result.add(entry);
5151
}
5252
} catch (IOException e) {
53-
e.printStackTrace();
53+
System.out.println("Couldn't retrieve directory contents for directory at " + dir.toString());
5454
}
5555
return result.toArray(new Path[0]);
5656
}

0 commit comments

Comments
 (0)