Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@pjazdzewski1990
Created July 13, 2016 20:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pjazdzewski1990/b6575c721e6790cb63166dcc91dad16b to your computer and use it in GitHub Desktop.
Save pjazdzewski1990/b6575c721e6790cb63166dcc91dad16b to your computer and use it in GitHub Desktop.
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