Skip to content

Commit 7c36eaf

Browse files
committed
Updated Error Handling + Log Messages
1 parent d0d2a89 commit 7c36eaf

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/main/kotlin/de/jakkoble/plugins/Routing.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,13 @@ fun Application.configureHTTP() {
2727
post(Fruit.path) {
2828
if (isInvalidKey(call.parameters["key"].toString())) return@post // Check if the Key is WRONG => Stop Here
2929
val fruit = call.receive<Fruit>() // Receive Content of Request as Fruit
30-
if (!Fruits.list.none { it.name == fruit.name }) error("Name already in use") // If name is already in the List throw IllegalStateException
30+
if (!Fruits.list.none { it.name == fruit.name }) { // Check if incomming Fruit is already in List
31+
println("[Failed] Adding Fruit '${fruit.name}' - Fruit already exists.")
32+
return@post
33+
}
3134
Fruits.list.add(fruit) // Add Fruit to Fruit List
3235
call.respond(HttpStatusCode.OK) // Respond Status Code for clean Communication
36+
println("[Success] Added Fruit '${fruit.name}' to Fruit List.")
3337
}
3438

3539
// Delete-Request with the companion object parameter of Fruit Class
@@ -38,6 +42,7 @@ fun Application.configureHTTP() {
3842
val name = call.receive<Fruit>().name // Receive Content of Request as Fruit
3943
Fruits.list.removeIf { it.name == name } // Removes the Element with the name of the Request item
4044
call.respond(HttpStatusCode.OK) // Respond Status Code for clean Communication
45+
println("[Success] Deleted Fruit '$name' from Fruit List.")
4146
}
4247
}
4348
}

0 commit comments

Comments
 (0)