Created
December 17, 2018 02:00
-
-
Save bigwheel/14e521488527f35bf6efed19c2453861 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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