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

org.http4k.jsonrpc.ErrorMessage.kt Maven / Gradle / Ivy

There is a newer version: 5.31.0.0
Show newest version
package org.http4k.jsonrpc

import org.http4k.format.Json

open class ErrorMessage(val code: Int, val message: String) {
    open fun  data(json: Json): NODE? = null

    operator fun  invoke(json: Json): NODE = json {
        val fields = listOf("code" to number(code), "message" to string(message))
        val data = data(json)
        json.obj(data?.let { fields + ("data" to it) } ?: fields)
    }

    companion object {
        val InvalidRequest = ErrorMessage(-32600, "Invalid Request")
        val MethodNotFound = ErrorMessage(-32601, "Method not found")
        val InvalidParams = ErrorMessage(-32602, "Invalid params")
        val InternalError = ErrorMessage(-32603, "Internal error")
        val ParseError = ErrorMessage(-32700, "Parse error")
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy