neworldlt
02/13/2018, 8:29 PMapplication/json
, I would like serialize exception using gson. If client asks text/html
, then simple html page and for text/plain
print only message.gildor
02/14/2018, 4:48 AMcy
02/14/2018, 7:50 AMinstall(ContentNegotiation) {
gson {
setPrettyPrinting()
}
}
install(StatusPages) {
exception<FileNotFoundException> { t ->
call.respond(...)
}
}
neworldlt
02/14/2018, 10:05 AMneworldlt
02/14/2018, 10:06 AMinstall(ContentNegotiation) {
val converter = JacksonConverter(objectMapper)
register(ContentType.Application.Json, converter)
}
install(StatusPages) {
exception<BackendException> { cause ->
call.respond(cause.responseStatus, cause.errorResponse)
}
exception<ValidationException> { cause ->
call.respond(HttpStatusCode.InternalServerError, ErrorResponse(OTHER, message = cause.localizedMessage))
}
}
neworldlt
02/14/2018, 10:10 AMErrorResponse()
to various content types. But for OK
responses I would like support only application/json
. It looks like separate ContentNegotiation
for StatusPages
. Is there any pattern to accomplish this?