classFinatraThriftExceptionMapper extends ExceptionMapper[Exception, ThriftException] with Logging
A generic com.twitter.finatra.thrift.exceptions.ExceptionMapper over the
java.lang.Exception exception type. This mapper attempts to translate other
exceptions to declared finatra-thrift/finatra_thrift_exception.thrift exceptions.
If you include the finatra-thrift/finatra_thrift_exception.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_exception.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.
Annotations
@Singleton()
Note
This is only applicable in scala since the FinatraThriftExceptionMapper uses
scala generated classes for the exceptions. We recommend for users including the
finatra-thrift/finatra_thrift_exception.thrift register this mapper in their
scala Servers.
A generic com.twitter.finatra.thrift.exceptions.ExceptionMapper over the java.lang.Exception exception type. This mapper attempts to translate other exceptions to declared
finatra-thrift/finatra_thrift_exception.thrift
exceptions.If you include the
finatra-thrift/finatra_thrift_exception.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_exception.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 in scala since the FinatraThriftExceptionMapper uses scala generated classes for the exceptions. We recommend for users including the
finatra-thrift/finatra_thrift_exception.thrift
register this mapper in their scala Servers.Using Finagle Thrift
Finatra Thrift Exception Mapping
src/main/thrift/finatra-thrift/finatra_thrift_exception.thrift