jvmMain.kr.jadekim.jext.ktor.extension.response.kt Maven / Gradle / Ivy
The newest version!
package kr.jadekim.jext.ktor.extension
import io.ktor.server.response.*
import io.ktor.server.routing.*
import kr.jadekim.common.exception.ErrorCode
import kr.jadekim.server.http.exception.HttpServerException
import kr.jadekim.server.protocol.ErrorResponse
import kr.jadekim.server.protocol.Response
import kr.jadekim.server.protocol.SuccessResponse
import java.util.*
suspend fun RoutingContext.success(
body: Any? = null,
meta: Response.Meta = Response.Meta(),
) = call.respond(SuccessResponse(body, meta))
suspend fun RoutingContext.error(
code: ErrorCode,
message: String,
data: Any? = null,
meta: Response.Meta = Response.Meta(),
) = call.respond(ErrorResponse(code, message, data, meta))
fun HttpServerException.toResponse(
locale: Locale? = null,
meta: Response.Meta = Response.Meta(),
) = toResponse(locale?.language, meta)
© 2015 - 2025 Weber Informatics LLC | Privacy Policy