io.fintrospect.renderers.JsonErrorResponseRenderer.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fintrospect_2.10 Show documentation
Show all versions of fintrospect_2.10 Show documentation
Library that adds self-documentation to Finagle server endpoint services
package io.fintrospect.renderers
import com.twitter.finagle.http.Response
import com.twitter.finagle.http.Status.{BadRequest, NotFound}
import io.fintrospect.formats.json.Argo.JsonFormat.{array, boolean, obj, string}
import io.fintrospect.formats.json.Argo.ResponseBuilder.implicits.{responseBuilderToResponse, statusToResponseBuilderConfig}
import io.fintrospect.parameters.InvalidParameter
object JsonErrorResponseRenderer {
def badRequest(badParameters: Seq[InvalidParameter]): Response = {
val messages = badParameters.map(p => obj(
"name" -> string(p.param.name),
"type" -> string(p.param.where),
"datatype" -> string(p.param.paramType.name),
"required" -> boolean(p.param.required),
"reason" -> string(p.reason)
))
BadRequest(obj("message" -> string("Missing/invalid parameters"), "params" -> array(messages)))
}
def notFound(): Response = { NotFound(obj("message" -> string("No route found on this path. Have you used the correct HTTP verb?"))) }
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy