I’m working on a way to handle errors that should show an error page in HTML format. But it’s not working, and instead of showing the error page, it’s giving back a default JSON message saying {"message": "Internal Server Error"}
.
Here is my controller:
@Controller("/mail")
class MailController {
@View("mail")
@Get("/")
fun index: Map<String, Any?>{
val res = HashMap<String, Any?>()
// throw Exception("This is a test exception")
return res
}
}
The error handler:
import io.micronaut.http.HttpStatus
@Controller("/err")
class ErrorController {
@View("500")
@Error(status = HttpStatus.INTERNAL_SERVER_ERROR, global = true)
fun errorHandler(e: Exception): Map<String, Any> {
return HashMap()
}
}