Júlio Santos
05/17/2021, 1:09 AMfun getMessages(locale: Locale = Locale.getDefault(), key: String): String {
val message = ResourceBundle.getBundle("messages", locale)
return message.getString(key)
}
fun StatusPages.Configuration.handle() {
exception<Exception> {
val response = mapOf(
"status" to 400,
"Code" to getMessages(key = "hello"),
"Message" to getMessages(key = "world")
)
call.respond(status = HttpStatusCode.BadRequest, message = response)
}
exception<EntityNotFoundException> {
val language = call.request.acceptLanguage()
val response = mapOf(
"status" to 400,
"Code" to getMessages(Locale("pt", "BR"), "hello"),
"Message" to getMessages(Locale("pt", "BR"), "world")
)
call.respond(HttpStatusCode.NotFound, message = response)
}
}