Skip to content

Commit

Permalink
Send TApplicationException to client if raised
Browse files Browse the repository at this point in the history
  • Loading branch information
aisk committed Jan 15, 2021
1 parent f7f8f11 commit df80fbb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/addressbook.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ service AddressBookService {
map<PhoneType, string> get_phones(1: string name);
bool sleep(1: i32 ms);
void close(1: i32 ms);
void raises(1: string msg);
}
14 changes: 14 additions & 0 deletions tests/test_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ def sleep(self, ms):
def close(self, ms):
return

def raises(self, msg):
raise TApplicationException(message=msg)


@pytest.fixture(scope="module")
def server(request):
Expand Down Expand Up @@ -273,3 +276,14 @@ def test_ssl_client_timeout():
def test_close_method():
with client() as c:
c.tclose(1)


def test_raises_method():
with client() as c:
try:
c.raises("foobarbaz")
except TApplicationException as e:
assert e.type == 0
assert e.message == "foobarbaz"
else:
raise ValueError("TApplicationException not raised")
2 changes: 2 additions & 0 deletions thriftpy2/thrift.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,8 @@ def process(self, iprot, oprot):

try:
result.success = call()
except TApplicationException as e:
return self.send_exception(oprot, api, e, seqid)
except Exception as e:
# raise if api don't have throws
if not self.handle_exception(e, result):
Expand Down

0 comments on commit df80fbb

Please sign in to comment.