Skip to content

Instantly share code, notes, and snippets.

@bigwheel
Created December 17, 2018 02:00
Show Gist options
  • Save bigwheel/14e521488527f35bf6efed19c2453861 to your computer and use it in GitHub Desktop.
Save bigwheel/14e521488527f35bf6efed19c2453861 to your computer and use it in GitHub Desktop.
case class ErrorResponseBody private(
`type`: URI,
title: String
)
// https://doc.akka.io/docs/akka-http/10.1.3/routing-dsl/rejections.html?language=scala#customising-rejection-http-responses
private val rfc7807RejectionHandler = RejectionHandler.default.mapRejectionResponse {
case res @ HttpResponse(_, _, entity: HttpEntity.Strict, _) =>
val message = entity.data.utf8String
res.copy(
entity = HttpEntity(
CustomMediaTypes.`application/problem+json`,
ErrorResponseBody(new URI("about:blank"), message).toJson.prettyPrint
)
)
case x => x
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment