Created
July 13, 2016 20:58
-
-
Save pjazdzewski1990/b6575c721e6790cb63166dcc91dad16b 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
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