Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class MicroserviceExceptionSerializer extends ExceptionSerializer {
override def serialize(exception: Throwable,
accept: java.util.Collection[MessageProtocol])
: RawExceptionMessage = {
val mp = MessageProtocol.fromContentTypeHeader(Optional.empty())
val defaultMessage = new RawExceptionMessage(
TransportErrorCode.InternalServerError,
mp,
ByteString.apply(exception.getMessage)
)
def getMessageForCompletionException(completionEx: CompletionException) =
completionEx.getCause match {
case ex: ServerError =>
new RawExceptionMessage(
TransportErrorCode.InternalServerError,
mp,
ByteString.apply(ex.msg)
)
case ex => defaultMessage
}
exception match {
case ex: CompletionException =>
getMessageForCompletionException(ex)
case ex: Throwable =>
defaultMessage
}
}
override def deserialize(message: RawExceptionMessage): Throwable = ???
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.