final classFinatraThriftExceptionMapper extends ExceptionMapper[Exception, Nothing] with Logging
A generic com.twitter.finatra.thrift.exceptions.ExceptionMapper over the
java.lang.Exception exception type intended for usage with generated Scala code.
This mapper attempts to translate other exceptions to declared
finatra-thrift/finatra_thrift_exceptions.thrift exceptions.
We recommend for users to include the finatra-thrift/finatra_thrift_exceptions.thrift and register
this mapper in their servers.
If you include the finatra-thrift/finatra_thrift_exceptions.thrift file in your
thrift service IDL and declare any of your service methods to throw one or more of the defined
thrift exceptions, i.e.,
using the FinatraThriftExceptionMapper will translate any Throwable into
one of the finatra_thrift_exceptions where appropriate for responding to the
client.
Exceptions returned from a thrift service which are not declared in the thrift
IDL are returned as a generic TApplicationException.
Usage
In your myservice.thrift, include the finatra-thrift/finatra_thrift_exceptions.thrift thrift IDL:
namespace java com.my_org.myservice.thriftjava
#@namespace scala com.my_org.myservice.thriftscala
include "finatra-thrift/finatra_thrift_exceptions.thrift"
Then in your MyService definition, declare methods to throw finatra_thrift_exceptions:
Adding this ExceptionMapper into your server will thus translate any of the handled
exceptions into a form that will serialize appropriately to the client.
Note, you can also mix usage with your own declared exception(s), e.g.,
You could then register an additional ExceptionMapper to translate Throwables
into MyServiceException as desired or return the exception directly from implemented
methods.
A generic com.twitter.finatra.thrift.exceptions.ExceptionMapper over the java.lang.Exception exception type intended for usage with generated Scala code. This mapper attempts to translate other exceptions to declared
finatra-thrift/finatra_thrift_exceptions.thrift
exceptions.We recommend for users to include the
finatra-thrift/finatra_thrift_exceptions.thrift
and register this mapper in their servers.If you include the
finatra-thrift/finatra_thrift_exceptions.thrift
file in your thrift service IDL and declare any of your service methods to throw one or more of the defined thrift exceptions, i.e.,using the FinatraThriftExceptionMapper will translate any Throwable into one of the finatra_thrift_exceptions where appropriate for responding to the client.
Exceptions returned from a thrift service which are not declared in the thrift IDL are returned as a generic
TApplicationException
.Usage
In your
myservice.thrift
, include thefinatra-thrift/finatra_thrift_exceptions.thrift
thrift IDL:namespace java com.my_org.myservice.thriftjava #@namespace scala com.my_org.myservice.thriftscala include "finatra-thrift/finatra_thrift_exceptions.thrift"
Then in your MyService definition, declare methods to throw finatra_thrift_exceptions:
Adding this ExceptionMapper into your server will thus translate any of the handled exceptions into a form that will serialize appropriately to the client.
Note, you can also mix usage with your own declared exception(s), e.g.,
exception MyServiceException { 1: string message }
Then in your MyService definition,
You could then register an additional ExceptionMapper to translate Throwables into
MyServiceException
as desired or return the exception directly from implemented methods.This is only applicable with generated Scala code since the FinatraThriftExceptionMapper uses generated Scala classes for the exception mapping. Users of generated Java code should use FinatraJavaThriftExceptionMapper.
Using Finagle Thrift
Finatra Thrift Exception Mapping
finatra-thrift/finatra_thrift_exceptions.thrift