com.mesosphere.cosmos.finch.IncompatibleAcceptHeader.scala Maven / Gradle / Ivy
The newest version!
package com.mesosphere.cosmos.finch
import com.mesosphere.cosmos.http.MediaType
import com.twitter.finagle.http.Fields
import com.twitter.finagle.http.Status
import io.circe.JsonObject
import io.circe.syntax._
case class IncompatibleAcceptHeader(available: Set[MediaType], specified: Set[MediaType]) extends RequestError {
val errType: String = "not_valid"
val status: Status = Status.BadRequest
val getData: Option[JsonObject] = Some(JsonObject.fromMap(Map(
"invalidItem" -> JsonObject.fromMap(Map(
"type" -> "header".asJson,
"name" -> "Accept".asJson
)).asJson,
"specified" -> specified.map(_.show).asJson,
"available" -> available.map(_.show).asJson
)))
val getHeaders: Map[String, String] = Map.empty
override def getMessage: String = {
val specifiedStr = specified.map(_.show).mkString(", ")
val availableStr = available.map(_.show).mkString(", ")
s"${Fields.Accept} header was [$specifiedStr] but should be one of [$availableStr]"
}
}