All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jvmMain.kr.jadekim.jext.ktor.extension.response.kt Maven / Gradle / Ivy

There is a newer version: 2.1.4
Show newest version
package kr.jadekim.jext.ktor.extension

import io.ktor.server.application.*
import io.ktor.server.response.*
import io.ktor.util.pipeline.*
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 PipelineContext<*, ApplicationCall>.success(
    body: Any? = null,
    meta: Response.Meta = Response.Meta(),
) = context.respond(SuccessResponse(body, meta))

suspend fun PipelineContext<*, ApplicationCall>.error(
    code: ErrorCode,
    message: String,
    data: Any? = null,
    meta: Response.Meta = Response.Meta(),
) = context.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