I am stuck at a place, I am using scala, tapir and circe.
sealed abstract class S1Error extends Product with Serializable
object S1Error {
final case class SError(error: SMError) extends S1Error
}
sealed abstract class SMError(message: String)
object SMError {
final case class SVError(message: String) extends SMError(message)
}
For tapir errorOut I am using this
val schemaVersionError: EndpointOutput.StatusMapping[SError] = statusMappingValueMatcher(
StatusCode.BadRequest,
jsonBody[SError]
.description("XXXX.")
) {
case SMError(SVError(_)) => true
case _ => false
}
Now because of this structure, the API result I get is
{
"error": {
"SVError": {
"message": "XXXXG"
}
}
}
where as ideally I would want a response as
"message": "XXXXG"
I can not change the error structure. Is there a way to wrap this error using a custom codec to get the result as required.