Logging the operation

Report a typo

Imagine you need to implement a page that does division. A user enters for example URL /division/12/3 and gets the answer: 4. You also need to log access to this page and possible errors when doing division.

How to correctly implement a routing handler for this page?

Reorder lines using drag or arrows. Adjust indentation with left buttons
                log.debug("Division is requested")
              
                routing {
              
                }
              
                get("/division/{a?}/{b?}") {
              
                } catch (e: Exception) {
              
                try {
              
                val result = call.parameters["a"]!!.toInt() / call.parameters["b"]!!.toInt()
              
                }
              
                call.respondText(result.toString())
              
                log.error(e.message)
              
                }
              
___

Create a free account to access the full topic